Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What I should change to basktest my strategy?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    What I should change to basktest my strategy?

    Hi,

    as I'm not good at programing and with the forum help, and some copy -paste, I managed to create an strategy, but I can't basktest it because somewhere in the code makes only for real-time trading.
    Can you help me and tell me what I should change to backtest it?
    And to optimize it?

    Here is the part of the code where I think I should make the changes:

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"estategia";
    Name = "Estrategia2";
    Calculate = Calculate.OnPriceChange;
    //EntriesPerDirection = 2;
    //EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = true;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; //ojo con las ordenes rejected
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 30;


    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;

    IsUnmanaged = true;


    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    Swing1 = Swing(Close, Convert.ToInt32(Fuerzaswing));
    }
    else if (State == State.Historical)
    {
    sessionIterator = new SessionIterator(Bars);
    exitOnCloseWait = false;
    }
    else if (State == State.Realtime)
    {
    // this needs to be run at least once before orders start getting placed.
    // I could do this when CurrentBar is 0 in OnBarUpdate,
    // but since this script only runs in real-time, I can trigger it once as the script transistions to real-time
    sessionIterator.GetNextSession(Time[0], true);
    }


    }



    Thanks a lot,
    aprendiz

    #2
    Hi aprendiz, thanks for your note.

    It looks like the way you are using the session iterator can be changed. It should not need to be instantiated every time in State.Historical. In the help guide example, it shows the SessionIterater initialized in State.DataLoaded and used in OnBarUpdate, so this would be the thing to change about this strategy to get it to work in a backtest.


    Please let me know if I can assist any further.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    44 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    65 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X