Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Automated trading for Futures

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

    Automated trading for Futures

    Hello I am trying to convert my equities strategy for futures.

    When I try to run a back test it doesn't work. Can you tell me what is wrong with my code. To me it should work.

    Code:
    	// See the Help Guide for additional information
    				IsInstantiatedOnEachOptimizationIteration	= true;
    				
    				AddPlot(Brushes.Orange, "PLOTA");
    				AddPlot(Brushes.Green, "PLOTB");
    			}
    			else if (State == State.Configure)
    			{
    				//SetProfitTarget(CalculationMode.Currency, 5000);
    				//SetStopLoss(CalculationMode.Currency, 1500);
    				AddDataSeries(BarsPeriodType.Month, 1);
    				AddDataSeries(BarsPeriodType.Day, 1);
    			}
    			else if (State == State.DataLoaded)
    			{
    				midbb = Bollinger(Close, 2, 20);
    				SMAmonth = SMA(BarsArray[1], 5);
    				DMI = DM(Close, 14);
    				ATRdaily = ATR(Close, 14);
    				ADXweek = ADX(BarsArray[2], 14);
    				StoConfirmWeek = Stochastics(5, 15, 3);
    				StoConfirmMonth = Stochastics(BarsArray[1], 5, 15, 3);
    				RSIweek = RSI(Close, 5, 3);
    				RSIdaily = RSI(BarsArray[2], 5, 3);
    				
    				
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			if (CurrentBars[0] < 5 || CurrentBars[1] < 5)
    				return;
    			
    			Values[0][0] = midbb.Middle[0];
    			Values[1][0] = SMAmonth[0];
    			
    			if (holdValue == 0
    			&& (Highs[0][4] < Highs[0][3])
    			&& (Lows[0][4] > midbb.Middle[4])
    			&& (Lows[0][3] > midbb.Middle[3])
    			&& (Lows[0][2] > midbb.Middle[2])
    			&& (Lows[0][1] > midbb.Middle[1])
    			&& (Highs[0][3] > Highs[0][2])
    			&& (Highs[0][3] > Highs[0][1]))
    			{
    				holdValue = Highs[0][3];
    			}
    			
    	
    			
    			if (holdValue != 0 && Lows[0][0] < midbb.Middle[0])
    			{
    				holdValue = 0;
    				Print("Reset of holdValue " + holdValue);
    			}
    			
    		
    			
    			if (holdValue != 0)
    			{
    				Print("High price at last condition was " + holdValue);
    			}
    			
    			if ((holdValue > midbb.Middle[0])
    			&& (Lows[1][2] >= SMAmonth[2])
    			&& (Lows[1][1] >= SMAmonth[1])
    			&& (Lows[1][0] >= SMAmonth[0])
    			&& (holdValue != 0)
    			//&& (ATRdaily[0] >= .75)
    			&& (RSIweek[0] >= 75)
    			//&& (RSIdaily[0] >= 75)
    			//&& (Slope(DMI.DiPlus, 1, 0) > 1)
    			//&& (Slope(DMI.DiMinus, 1, 0) < -1)
    			//&& (DMI.DiPlus[0] >= 50)
    			//&& (StoConfirmWeek.K[0] > StoConfirmWeek.D[0])
    			//&& (StoConfirmMonth.K[0] > StoConfirmMonth.D[0])
    			&& (Highs[0][0] > holdValue))
    			{
    				int myQuantity = (int) ((1200)/(holdValue - midbb.Middle[0]));
    				EnterLong(1, @"");
    				holdValue = 0;
    			} else if (holdValue != 0 && Highs[0][0] > holdValue + .02)
    			{
    				holdValue = 0;
    				Print("Reset of holdValue" + holdValue);
    			}
    			
    			if (Lows[0][0] < SMAmonth[0])
    			{
    				ExitLong();
    			}
    			
    			if (holdValueShort == 0
    			&& (Lows[0][4] > Lows[0][3])
    			&& (Highs[0][4] < midbb.Middle[4])
    			&& (Highs[0][3] < midbb.Middle[3])
    			&& (Highs[0][2] < midbb.Middle[2])
    			&& (Highs[0][1] < midbb.Middle[1])
    			&& (Lows[0][3] < Lows[0][2])
    			&& (Lows[0][3] < Lows[0][1]))
    			{
    				holdValueShort = Lows[0][3];
    			}
    			
    			if (holdValueShort != 0 && Highs[0][0] > midbb.Middle[0])
    			{
    				holdValueShort = 0;
    				Print("Reset of holdValueShort " + holdValueShort);
    			}
    			
    			
    			if (holdValueShort != 0)
    			{
    				Print("Low price at last condition was " + holdValueShort);
    			}
    			
    			if ((holdValueShort < midbb.Middle[0])
    			&& (Highs[1][2] <= SMAmonth[2])
    			&& (Highs[1][1] <= SMAmonth[1])
    			&& (Highs[1][0] <= SMAmonth[0])
    			&& (holdValueShort != 0)
    			//&& (ATRdaily[0] >= .75)
    			&& (RSIweek[0] <= 25)
    			//&& (RSIdaily[0] <= 25)
    			//&& (Slope(DMI.DiPlus, 1, 0) < -1)
    			//&& (Slope(DMI.DiMinus, 1, 0) > 1)
    			//&& (DMI.DiMinus[0] >= 50)
    			//&& (StoConfirmWeek.K[0] < StoConfirmWeek.D[0])
    			//&& (StoConfirmMonth.K[0] < StoConfirmMonth.D[0])
    			&& (Lows[0][0] < holdValueShort))
    			{
    				int myQuantity = (int) ((1200)/(midbb.Middle[0]) - holdValue);
    				EnterShort(1, @"");
    				holdValueShort = 0;
    			} else if (holdValueShort != 0 && Lows[0][0] < holdValueShort - .02)
    			{
    				holdValueShort = 0;
    				Print("Reset of holdValueShort" + holdValueShort);
    			}
    			
    			if (Highs[0][0] > SMAmonth[0])
    			{
    				ExitShort();
    			}
    		}
    	}
    }

    #2
    Hello dorony,

    Thanks for your post.

    As a check of your data, please run the strategy SampleMACrossover on the same data and the same period. If the strategy places orders then that would confirm you have the data for the instrument.

    When you run the strategy in the analyzer, do you see any error messages listed in the "log" tab of the control center related to the strategy?

    It appears the strategy is adding Monthly bars and daily bars, what bars are you setting the strategy on in the analyzer (I'm referencing these as chart bars)?

    Does your analysis period exceed the current bars check considering whatever the chart bars are and the 5 months of monthly bars?

    You have a few print statements, do you see any print output?

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    72 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    143 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    76 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    47 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    51 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X