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

Help with code please.

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

    Help with code please.

    Hi, I am coding Gann's Hi Lo Activator.
    I have run into a problem that requires some assistance. I have attached the file here and have it all commented so you can easily follow what's, what. I have also attached a screen shot showing it as is.
    The problem I have is that there should only be one plot, or the other, printing at any given time. Clearly this is not happening. The reason it is not happening is that the "trigger", for the trend state to change only has to occur once, then the state should remain as is until the opposite "trigger" occurs. The "triggers" are based on closes above and below the 2 plots. But the problem occurs when the close is in between the 2 plots. Because the code is checking for the "trigger" on each bar. For instance an up trend can be triggered with a close above the Hi plot, which makes the Lo plot print, but then the next bar perhaps closes below the Hi plot but above the Lo plot and because it hasn't closed above the Hi plot will print the Hi plot again, which I don't wan't it to, not until such time as the down trend trigger occurs.
    I just can't figure out a way to say what I can say in english, in code.
    Look at the code you can see my "if", "else" statement, "else" is in english to convey to you what I think I need to say?

    So, if the up trend state is triggered, change the plot colours as such.
    (Once this triggers, do nothing until the down trend state is triggered.)
    if the down trend state is triggered, change the plot colours as such.
    (Once this triggers, do nothing until the up trend state is triggered.)
    else, do nothing.

    Please help I'm going mad trying to figure this out!

    Cheers,
    Ken.
    Attached Files

    #2
    Hello KennyK,

    Thanks for your post.

    You can use a bool variable as a "switch" to set your plot brushes.

    The bool would be set true or false inside the conditions you have.

    Then you can have another set of if statements based on the bool setting of true or false to then set the plotbrushes as you wish.

    Because the bool is only set when the conditions you have are true, the plots will remain colored until the bool state is switched by your conditions.

    It is recommended that you create local instances of any indicators that your code calls. For example, you are calling the SMA a couple of times. While a couple of calls in not a significant performance issue you would want to develop your coding to conform to the best practices to avoid performance issues, please see the section "Performance practices" in this link:https://ninjatrader.com/support/help..._practices.htm The example actually shows how to use the SMA.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul

      Thanks Paul,
      I had already started looking at a switch but wasn't sure if it was the best way to go. So your reply gave me that direction and a good explanation how to go about it.
      Consequently I have it all completed and working properly.

      On a different subject:
      I am wanting to make a change to the code that changes the colour of Kagi swings. But I looked at Kagi and another bar type and found no code relating to colour. Why is that?
      Where would I look to make a change like that?

      Cheers,
      Ken.

      Comment


        #4
        Found it.

        Found what I was looking for in "ChartStyle", rather than "BarType".
        Looks to be complicated though?
        Would it be any better / easier to change the way Kagi changes colour from an indicator?

        Also, Is there a simple way from inside an indicator to pre-set the candle / bar width, and outline and wick width?

        Cheers,
        Ken.
        Last edited by KennyK; 11-05-2017, 02:53 PM. Reason: add something

        Comment


          #5
          Hello KennyK,

          Thanks for your reply.

          You can change the bar color, in an indicator, using BarBrush: https://ninjatrader.com/support/help.../?barbrush.htm

          Alternatively, in state,Data loaded you can try, for example:

          ChartControl.BarWidth = 10; // reference: https://ninjatrader.com/support/help...l_barwidth.htm
          ChartBars.Properties.ChartStyle.Stroke.Pen = new Pen(Brushes.Magenta, 6); // not documented
          ChartBars.Properties.ChartStyle.Stroke2.Pen = new Pen(Brushes.CornflowerBlue, 3); // not documented
          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Christopher_R, Today, 12:29 AM
          0 responses
          9 views
          0 likes
          Last Post Christopher_R  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          166 responses
          2,235 views
          0 likes
          Last Post sidlercom80  
          Started by thread, Yesterday, 11:58 PM
          0 responses
          3 views
          0 likes
          Last Post thread
          by thread
           
          Started by jclose, Yesterday, 09:37 PM
          0 responses
          8 views
          0 likes
          Last Post jclose
          by jclose
           
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          10 responses
          1,415 views
          0 likes
          Last Post Traderontheroad  
          Working...
          X