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

Passing parameters from Strategy to Indicator via Add()

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

    Passing parameters from Strategy to Indicator via Add()

    Hi,
    I am trying to add a custom indicator to a strategy and pass it some parameters derived from the strategy

    Unfortunately, when I run a print to Output of the value that the Indicator is receiving, the only value i get is 1.

    What am I doing wrong?

    Thanks.



    Strategy:-

    double param1;
    double param2;

    protected override void Initialize()
    {
    setParameters();

    Add(MyIndicator( param1, param2));
    }

    setParameters()
    {
    param1 = 0.9;
    param2 = 0.4;
    }

    Indicator:-

    public class MyIndicator : Indicator
    {
    #region Variables
    // Wizard generated variables
    private double param1 = 0.5; // Default setting for param1
    private double param2 = 0.5; // Default setting for param2
    // User defined variables (add any user defined variables below)
    double val;
    double lastDailyClose = 0.0;
    double LongStopIn;
    double ShortStopIn;
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "LongEntry"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "ShortEntry"));
    Overlay = true;
    Add(PeriodType.Day, 1);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // 3 Days lookback
    if (CurrentBar < 4200) //700
    return;

    // OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
    // We only want to process events on our primary Bars object (main instrument) (index = 0) which
    // is set when adding the strategy to a chart
    if (BarsInProgress != 0)
    return;

    if (Bars.FirstBarOfSession)
    {
    val= calcVal();
    lastDailyClose = Closes[1][0];
    LongStopIn = lastDailyClose + (val*longStopEntry);
    ShortStopIn = lastDailyClose - (val*shortStopEntry);

    // Only ever see value 1.........
    string str = "INDICATOR------longStopEntry=" + longStopEntry;
    Print(str);
    str = "INDICATOR-------shortStopEntry=" + shortStopEntry;
    Print(str);
    }
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    LongEntry.Set(LongStopIn);
    ShortEntry.Set(ShortStopIn);
    }

    #2
    abfc123, unfortunately strategies would not cross communicate to other scripts.
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cls71, Today, 04:45 AM
    0 responses
    1 view
    0 likes
    Last Post cls71
    by cls71
     
    Started by mjairg, 07-20-2023, 11:57 PM
    3 responses
    213 views
    1 like
    Last Post PaulMohn  
    Started by TheWhiteDragon, 01-21-2019, 12:44 PM
    4 responses
    544 views
    0 likes
    Last Post PaulMohn  
    Started by GLFX005, Today, 03:23 AM
    0 responses
    3 views
    0 likes
    Last Post GLFX005
    by GLFX005
     
    Started by XXtrader, Yesterday, 11:30 PM
    2 responses
    12 views
    0 likes
    Last Post XXtrader  
    Working...
    X