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
Comment