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

Stop percent optimization

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

    Stop percent optimization

    Hi

    i try a simple code with a stop calculation.mode percent

    i would like to optimize the percent of the stop, but i don't know how to do it.

    when i write :

    #region Varaibles
    privateint stop = 1;

    OnBarUpdate
    SetStopLoss("X pourcent", CalculationMode.Percent, stop/100, false);

    it is not working... when a trade is initiated, it is directly stopped

    if i write
    #region Varaibles
    privateint stop = 0.01;

    it is not working as well (error CS0266)


    In the 2 cases on the #region Properties i write

    [Description("stop en pourcentage")]
    [GridCategory(
    "Parameters")]
    publicint Stop
    {
    get { return stop; }
    set { stop = Math.Max(1, value); }
    }


    can you help ?
    thx

    #2
    Hello Thomas79,

    Thank you for your post.

    Set the variable as a double. Below is an example that will optimize properly:
    Code:
            #region Variables		
            private double stop = 0.1;
            #endregion
    
            
            protected override void Initialize()
            {
               	SetStopLoss("entry", CalculationMode.Percent, stop, false);
            }
    		
    		protected override void OnBarUpdate()
    		{
    			if(Close[0]>Close[1])
    			{
    				EnterLong(1,"entry");
    			}
    		}
    
    		
            #region Properties
            [Description("Percent Stop")]
    		[GridCategory("Parameters")]
    		public double Stop
    		{
    			get { return stop; }
    			set { stop = Math.Max(0.1, value); }
    		}
    Please let me know if you have any questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by bmartz, Today, 09:30 AM
    2 responses
    11 views
    0 likes
    Last Post bltdavid  
    Started by f.saeidi, Today, 11:02 AM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by geotrades1, Today, 10:02 AM
    4 responses
    12 views
    0 likes
    Last Post geotrades1  
    Started by rajendrasubedi2023, Today, 09:50 AM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by lorem, Today, 09:18 AM
    2 responses
    11 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X