Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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?
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    148 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    5 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    33 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    5 views
    0 likes
    Last Post tkaboris  
    Started by GussJ, 03-04-2020, 03:11 PM
    16 responses
    3,283 views
    0 likes
    Last Post Leafcutter  
    Working...
    X