Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 04:34:00 +0000



Post From: Very low programming experience, help w/ simple trading system

[2014-04-07 02:09:28]
cazeek - Posts: 33
Thanks guys,

I have it now working in terms of trade execution / back testing, but the actual moving averages and arrows are not showing up on the chart. It's actually a little weird, when I first load the study, and click "Apply", I can see the moving average lines, but as soon as I click "OK", the lines disappear. Can you please take a look at the code again and let me know what I'm missing?

SCSFExport scsf_SC_MACrossover(SCStudyGraphRef sc)
{

  SCInputRef FastLength = sc.Input[0];
  SCInputRef SlowLength = sc.Input[1];

  SCSubgraphRef Buy = sc.Subgraph[0];
  SCSubgraphRef Sell = sc.Subgraph[1];
  
  SCSubgraphRef FastMA = sc.Subgraph[2];
  SCSubgraphRef SlowMA = sc.Subgraph[3];
  
  
  if (sc.SetDefaults)
  {

    // Set the configuration and defaults

    sc.GraphName = "MA Crossover";

    sc.StudyDescription = "Simple MA Crossover System";

    sc.AutoLoop = 1; // true
    sc.GraphRegion = 0;
    sc.FreeDLL = 1;
    sc.CalculationPrecedence = LOW_PREC_LEVEL;

    // Automated Trade Variables
    sc.AllowMultipleEntriesInSameDirection = false;
    sc.MaximumPositionAllowed = 250000;
    sc.SupportReversals = true;  
    sc.SendOrdersToTradeService = false;
    sc.AllowOppositeEntryWithOpposingPositionOrOrders = false;
    sc.SupportAttachedOrdersForTrading = false;
    sc.CancelAllOrdersOnEntriesAndReversals= true;
    sc.AllowEntryWithWorkingOrders = false;
    sc.CancelAllWorkingOrdersOnExit = true;
    
    sc.AllowOnlyOneTradePerBar = true;

    sc.MaintainTradeStatisticsAndTradesData = true;
    
    //

    FastLength.Name = "Fast Moving Average Length";
    FastLength.SetInt(10);

    SlowLength.Name = "Slow Moving Average Length";
    SlowLength.SetInt(100);

    Buy.Name = "Buy";
    Buy.DrawStyle = DRAWSTYLE_ARROWUP;
    Buy.DataColor[sc.Index] = RGB(0,255,0);
    Buy.LineWidth = 2;

    Sell.Name = "Sell";
    Sell.DrawStyle = DRAWSTYLE_ARROWDOWN;
    Sell.DataColor[sc.Index] = RGB(255,0,0);
    Sell.LineWidth = 2;
    
    FastMA.Name = "Fast Moving Average";
    FastMA.DrawStyle = DRAWSTYLE_LINE;
    FastMA.DataColor[sc.Index] = RGB(0,255,255);
    FastMA.LineWidth = 2;
    
    SlowMA.Name = "Slow Moving Average";
    SlowMA.DrawStyle = DRAWSTYLE_LINE;
    SlowMA.DataColor[sc.Index] = RGB(125,255,255);
    SlowMA.LineWidth = 2;
    
    return;
  }

  // only process at the close of the bar; if it has not closed don't do anything
  if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_NOT_CLOSED)
  {
    return;
  }

  // Calculate moving averages, store into FastMA and SlowMA
  sc.SimpleMovAvg(sc.Close,FastMA,FastLength.GetInt());
  sc.SimpleMovAvg(sc.Close,SlowMA,SlowLength.GetInt());  

  if (sc.CrossOver(FastMA, SlowMA) == CROSS_FROM_BOTTOM)
  {
    Buy[sc.Index] = sc.Low[sc.Index] - sc.TickSize;
    
    s_SCNewOrder order;
    order.OrderQuantity = 250000;
    order.OrderType = SCT_ORDERTYPE_MARKET;

    sc.BuyEntry(order);
  }
  
  if (sc.CrossOver(FastMA, SlowMA) == CROSS_FROM_TOP)
  {
    Sell[sc.Index] = sc.High[sc.Index] + sc.TickSize;
    
    s_SCNewOrder order;
    order.OrderQuantity = 250000;
    order.OrderType = SCT_ORDERTYPE_MARKET;
    
    sc.SellEntry(order);
  }

}