Login Page - Create Account

Support Board


Date/Time: Thu, 06 Mar 2025 19:12:17 +0000



[Programming Help] - Accurate Trading System Replay Issues

View Count: 505

[2022-02-09 17:22:24]
SelimEker - Posts: 13
Hello,

I am new here, I have developed a Trading System using ASCIL advanced studies and whenever I'm testing it I am getting strange behaviours from the Accurate Trading System. While my code might definitely not the cleanest it produces the desired results in Tick By Tick replay or when using "live data".

The trading system consists of 3 parts.
1. Placing an order when a study gives a non zero signal and other conditions are met.
2. Modifying the order to follow the price given by a study
3. Cancelling the order if the conditions are not met anymore.

Currently I do the tasks in the following order and I am getting a "coherent" result from the Accurate Back Testing: First I try to Modify an existing order and if not possible I create a new order ( basically 2 -> 1 ).
Whenever i try to then add the step of cancelling the order (2->1->3) and do test on multiple days, 3 step never occurs (but if i use the tick by tick or do it on a single day it works).

One day i tried to shift a little bit the if and else if conditions i am working with (hoping to make everything more clear and logic) so i tried combining in the 1->2->3 order but then the Accurate Trading System backtest generated no trades at all..So i gave up and came back to the 2->1.


I would appreciate if you could enlighten me on how to make my code Accurate Trading System Back Test proof :D

I will stay at your disposal to provide anything you need. (The issue might be in some of the if condition, maybe the global variable (ActiveScalpPresent). (Following is how my 2->1 is looking with the 3 as a toggle).

Cheers :)



  if (sc.Index < sc.ArraySize - 1 && LONGsignalArray[sc.Index] != 0 && (TradingAllowed || Input_AllowTradingOutsideDuringTimeRange.GetYesNo() ) )
  {

    s_SCTradeOrder ExistingOrderBuy;
    sc.GetOrderByOrderID(BuyInternalOrderID, ExistingOrderBuy);

    if (LONGsignalArray[sc.Index - 1] != 0 && sc.GetOrderByOrderID(BuyInternalOrderID, ExistingOrderBuy) != SCTRADING_ORDER_ERROR && ExistingOrderBuy.BuySell == BSE_BUY && ExistingOrderBuy.OrderStatusCode == SCT_OSC_OPEN && LONGsignalArray[sc.Index - 1] != LONGsignalArray[sc.Index]) // ExistingOrderBuy.OrderStatusCode != SCT_OSC_FILLED
    {
      s_SCNewOrder ModifyOrder;
      ModifyOrder.InternalOrderID = BuyInternalOrderID;
      ModifyOrder.Price1 = LONGsignalArray[sc.Index] + sc.TickSize;
      //ModifyOrder.Stop1Price = sc.Low[sc.Index] - 2 * sc.TickSize;

      //New
      s_SCNewOrder ModifyStop;
      ModifyStop.InternalOrderID = BuyStop1OrderID;
      ModifyStop.Price1 = sc.Low[sc.Index] - 2 * sc.TickSize;

      sc.ModifyOrder(ModifyOrder);
      sc.ModifyOrder(ModifyStop);



    }
    else if (( !ShortErgoEnabled.GetYesNo() || ErgoLocaleSlopePosNegValue >= 0) && ( !LongErgoEnabled.GetYesNo() || Ergo30sSlopePosNegValue >= 0) && ActiveScalpPresent == false)
    {

      NewOrder.Price1 = LONGsignalArray[sc.Index] + sc.TickSize;
      NewOrder.Stop1Price = sc.Low[sc.Index] - 2 *sc.TickSize ;


      int Result = (int)sc.BuyEntry(NewOrder);
      if (Result > 0) //If there has been a successful order entry, then draw an arrow at the low of the bar.
      {
        Subgraph_BuyEntry[sc.Index] = sc.Low[sc.Index];
        ActiveScalpPresent = true;

        // Remember the order IDs for subsequent modification and cancellation
        BuyTarget1OrderID = NewOrder.Target1InternalOrderID;
        BuyStop1OrderID = NewOrder.Stop1InternalOrderID;
        BuyInternalOrderID = NewOrder.InternalOrderID;

        SCString DataString;
        DataString.Format("Buy Order !");
        sc.AddMessageToLog(DataString, 1);

      }
    }

    if (CancelOrderEnabled.GetYesNo())
    {
      // Cancelling Buy if condition changes. ( && if both have to change || if one or the other !)
      if (((!ShortErgoEnabled.GetYesNo() || ErgoLocaleSlopePosNegValue < 0) || (!LongErgoEnabled.GetYesNo() || Ergo30sSlopePosNegValue < 0)) && ActiveScalpPresent == true && ExistingOrderBuy.OrderStatusCode == SCT_OSC_OPEN && sc.GetOrderByOrderID(BuyInternalOrderID, ExistingOrderBuy) != SCTRADING_ORDER_ERROR)
      {
        sc.CancelOrder(BuyInternalOrderID);
        ActiveScalpPresent = false;
        SCString DataString;
        DataString.Format("Buy Order Canceled due to condition changed, Scalp Is Available to use Now !");
        sc.AddMessageToLog(DataString, 1);
      }
    }
  }


Date Time Of Last Edit: 2022-02-12 13:22:28

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account