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

Switch or else statement help

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

    Switch or else statement help

    The KeltnerChannel code is as follows:
    Code:
    [COLOR=black][FONT=Courier New][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]{[/SIZE][/FONT][/SIZE][/FONT][/FONT][/COLOR]
    [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][COLOR=black]diff.Set(High[[/COLOR][/FONT][/SIZE][/FONT][/SIZE][COLOR=black][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] - Low[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] middle = SMA(Typical, Period)[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]];[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] offset = SMA(diff, Period)[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] * offsetMultiplier;[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] upper = middle + offset;[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] lower = middle - offset;[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]Midline.Set(middle);[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]Upper.Set(upper);[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]Lower.Set(lower);[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [/SIZE][/FONT][/COLOR][/FONT]
    How do I make a switch, or else statement?

    If I want the Lower and Upper band plot to switch how would I write this expression?

    Would it be something like:
    If bar 1 < bar 0 then plot lower.set(lower) or else if bar 1 > bar 0 then plot Upper.set

    I have attached a picture of my example with the Plot Upper being LimeGreen and the Plot Lower being the Red.

    This way instead of a constant channel it would switch ploting styles.

    Thanks for the help in advance.
    Attached Files

    #2
    Hello,

    Thanks for the forum post.

    Unfortunately I'm unable to create this code for you. However I can link you to some information on this and also point you to our NinjaScript consultants that can assist you with coding this. I will also leave this open so a member of the community can respond if they would like.



    Also,

    You can contact one of our NinjaScript consultants to assist you with coding this or you can use our NinjaScript guide and forums to code this indicator yourself if you are a programmer.


    NinjaScript Consultants:


    NinjaScript Help Guide:



    Let me know if I can be of further assistance.

    Comment


      #3
      Originally posted by skikg View Post
      The KeltnerChannel code is as follows:
      Code:
      [COLOR=black][FONT=Courier New][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]{[/SIZE][/FONT][/SIZE][/FONT][/FONT][/COLOR]
      [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][COLOR=black]diff.Set(High[[/COLOR][/FONT][/SIZE][/FONT][/SIZE][COLOR=black][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] - Low[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT]
      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] middle = SMA(Typical, Period)[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]];[/SIZE][/FONT]
      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] offset = SMA(diff, Period)[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] * offsetMultiplier;[/SIZE][/FONT]
      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] upper = middle + offset;[/SIZE][/FONT]
      [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] lower = middle - offset;[/SIZE][/FONT]
      [SIZE=2][FONT=Courier New]Midline.Set(middle);[/FONT][/SIZE]
      [SIZE=2][FONT=Courier New]Upper.Set(upper);[/FONT][/SIZE]
      [SIZE=2][FONT=Courier New]Lower.Set(lower);[/FONT][/SIZE]
      [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
      [/SIZE][/FONT][/COLOR][/FONT]
      How do I make a switch, or else statement?

      If I want the Lower and Upper band plot to switch how would I write this expression?

      Would it be something like:
      If bar 1 < bar 0 then plot lower.set(lower) or else if bar 1 > bar 0 then plot Upper.set

      I have attached a picture of my example with the Plot Upper being LimeGreen and the Plot Lower being the Red.

      This way instead of a constant channel it would switch ploting styles.

      Thanks for the help in advance.
      Code:
      if (//Conditions to plot upper)
      {
      Upper.Set(upper);
      Lower.Reset();
      }
      else if (//Conditions to plot lower)
      {
      Upper.Reset();
      Lower.Set(lower);
      }
      Of course, if upper plot and lower plot are the only possibilities, then you can just use an "else" instead of an "if else".

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by reynoldsn, Today, 02:34 PM
      0 responses
      5 views
      0 likes
      Last Post reynoldsn  
      Started by nightstalker, Today, 02:05 PM
      0 responses
      9 views
      0 likes
      Last Post nightstalker  
      Started by llanqui, Yesterday, 09:59 AM
      8 responses
      28 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by quicksandatl, Today, 01:39 PM
      1 response
      6 views
      0 likes
      Last Post quicksandatl  
      Started by md4866, 05-01-2024, 08:15 PM
      2 responses
      18 views
      0 likes
      Last Post md4866
      by md4866
       
      Working...
      X