NexusFi: Find Your Edge


Home Menu

 





Need Help fix this errors on my code for a Two Legged Automated Strategy


Discussion in NinjaTrader

Updated
    1. trending_up 734 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 4 posts
    2. attach_file 1 attachments




 
Search this Thread

Need Help fix this errors on my code for a Two Legged Automated Strategy

  #1 (permalink)
 duckensm 
New York New york
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 39 since Jul 2022
Thanks Given: 7
Thanks Received: 5

please help fix these errors

the name 'PrifiTargetMoveType does not exist in current context on line 85 and 86

no overload for 'SetStopLoss' takes 1 arguments on line 89

the code is below

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.Gui.NinjaScript;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
using NinjaTrader.NinjaScript.Strategies;
//TwoLegged Strategy By Duckens M
namespace NinjaTrader.NinjaScript.Strategies
{
public class MyTwoLeggedPullback1 : Strategy
{
private int target1;
private int target2;
private int stopLoss;
private int trailingStop;

protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "A two legged pullback strategy with added target 1 and target 2 levels and a trailing stop";
Name = "MYTwoLeggedPullback1";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;

// Set target 1 and target 2 levels
target1 = 15;
target2 = 30;

// Set stop loss level
stopLoss = 10;

// Set trailing stop level
trailingStop = 5;
}
}

protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;

// Buy entry logic
if (Close[0] > Close[1] && Close[1] > Close[2])
{
EnterLong(1, "Long");
}

// Sell entry logic
if (Close[0] < Close[1] && Close[1] < Close[2])
{
EnterShort(1, "Short");
}

// Set target 1 and target 2 levels
SetProfitTarget(target1, ProfitTargetMoveType.Trailing, trailingStop);
SetProfitTarget(target2, ProfitTargetMoveType.Trailing, trailingStop);

// Set stop loss level
SetStopLoss(stopLoss);
}
}
}

Attached Thumbnails
Click image for larger version

Name:	Captureerror.JPG
Views:	46
Size:	37.4 KB
ID:	329588  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
What broker to use for trading palladium futures
Commodities
Quant vue
Trading Reviews and Vendors
REcommedations for programming help
Sierra Chart
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #2 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

SetStopLoss(CalculationMode.Price, stopLoss);

I don't know where this ProfitTargetMoveType.Trailing is coming from, SetProfitTarget() can't be use with this.

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
  #3 (permalink)
 duckensm 
New York New york
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 39 since Jul 2022
Thanks Given: 7
Thanks Received: 5


the StopLoss error fix, but the other 2 errors are still there but Thank you for fixing the stoploss

I'm still in need of help fixing lines 85 and 86 in the picture below



sam028 View Post
SetStopLoss(CalculationMode.Price, stopLoss);

I don't know where this ProfitTargetMoveType.Trailing is coming from, SetProfitTarget() can't be use with this.


Started this thread Reply With Quote
  #4 (permalink)
 duckensm 
New York New york
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 39 since Jul 2022
Thanks Given: 7
Thanks Received: 5

Sam028 can you please fix it the way you know how, I just need to add target1 and target2 with trailing stop to the code.
Thank you


sam028 View Post
SetStopLoss(CalculationMode.Price, stopLoss);

I don't know where this ProfitTargetMoveType.Trailing is coming from, SetProfitTarget() can't be use with this.


Started this thread Reply With Quote
  #5 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,176
Thanks Received: 6,020

Look in the help file:
https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?setprofittarget.htm

You are using the method in the OnBarUpdate() method.
Try to define it here:


Quoting 
protected override void OnStateChange()
{
if (State == State.Configure)
{
// Submits a profit target order 10 ticks away from the avg entry price
SetProfitTarget(CalculationMode.Ticks, 10);
}
}


Reply With Quote




Last Updated on February 5, 2023


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts