Login Page - Create Account

Support Board


Date/Time: Mon, 23 Dec 2024 00:46:57 +0000



Post From: ASCIL trading examples that come with SC

[2015-05-16 20:42:52]
User120827 - Posts: 77
hi

This was the example crossover code that is with many other codes under tradingsystems file in the ACS soure folder.

SCSFExport scsf_SC_TradingCrossOverExample(SCStudyGraphRef sc)



SCSFExport scsf_SC_TradingCrossOverExample(SCStudyGraphRef sc)
{

  SCInputRef Line1Ref = sc.Input[0];
  SCInputRef Line2Ref = sc.Input[1];

  SCSubgraphRef BuyEntry = sc.Subgraph[0];
  SCSubgraphRef SellEntry = sc.Subgraph[1];

  if (sc.SetDefaults)
  {

    // Set the configuration and defaults

    sc.GraphName = "Trading CrossOver Example";

    sc.StudyDescription = "An example of a trading system that enters a new position or \
               reverses an existing one on the crossover of two study Subgraphs. \
               When line1 crosses line2 from below, the system will look to be long. \
               When line1 crosses line2 from above, the system will look to be short.";

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

    Line1Ref.Name = "Line1";
    Line1Ref.SetStudySubgraphValues(1, 0);

    Line2Ref.Name = "Line2";
    Line2Ref.SetStudySubgraphValues(1, 0);

    BuyEntry.Name = "Buy";
    BuyEntry.DrawStyle = DRAWSTYLE_POINTHIGH;
    BuyEntry.LineWidth = 3;

    SellEntry.Name = "Sell";
    SellEntry.DrawStyle = DRAWSTYLE_POINTLOW;
    SellEntry.LineWidth = 3;

    sc.AllowMultipleEntriesInSameDirection = false;
    sc.MaximumPositionAllowed = 5;
    sc.SupportReversals = true;

    // This is false by default. Orders will not go to the external connected trading service.
    sc.SendOrdersToTradeService = false;

    sc.AllowOppositeEntryWithOpposingPositionOrOrders = false;

    // This can be false in this function because we specify Attached Orders directly with the order which causes this to be considered true when submitting an order.
    sc.SupportAttachedOrdersForTrading = false;

    sc.CancelAllOrdersOnEntriesAndReversals= true;
    sc.AllowEntryWithWorkingOrders = false;
    sc.CancelAllWorkingOrdersOnExit = true;

    // Only 1 trade for each Order Action type is allowed per bar.
    sc.AllowOnlyOneTradePerBar = true;

    //This needs to be set to true when a trading study uses trading functions.
    sc.MaintainTradeStatisticsAndTradesData = true;


    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;
  }


  // using the line1Ref and line2Ref input variables, retrieve the subgraph arrays into line1, line2 arrays respectively
  SCFloatArray line1;
  sc.GetStudyArrayUsingID(Line1Ref.GetStudyID(), Line1Ref.GetSubgraphIndex(), line1);

  SCFloatArray line2;
  sc.GetStudyArrayUsingID(Line2Ref.GetStudyID(), Line2Ref.GetSubgraphIndex(), line2);

  // code below is where we check for crossovers and take action accordingly

  if (sc.CrossOver(line1, line2) == CROSS_FROM_BOTTOM)
  {

    // mark the crossover on the chart
    BuyEntry[sc.Index] = 1;

    // Create a market order and enter long.
    s_SCNewOrder order;
    order.OrderQuantity = 1;
    order.OrderType = SCT_ORDERTYPE_MARKET;

    sc.BuyEntry(order);
  }

  if (sc.CrossOver(line1, line2) == CROSS_FROM_TOP)
  {


    // mark the crossover on the chart
    SellEntry[sc.Index] = 1;

    // create a market order and enter short
    s_SCNewOrder order;
    order.OrderQuantity = 1;
    order.OrderType = SCT_ORDERTYPE_MARKET;

    sc.SellEntry(order);
  }
}






i think the function I was in this section I was hoping to modify or add to the existing code.

if (sc.CrossOver(line1, line2) == CROSS_FROM_BOTTOM)
  {

    // mark the crossover on the chart
    BuyEntry[sc.Index] = 1;

    // Create a market order and enter long.
    s_SCNewOrder order;
    order.OrderQuantity = 1;
    order.OrderType = SCT_ORDERTYPE_MARKET;

    sc.BuyEntry(order);
  }