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

Separating chart reading and trade logic / dependencies between script

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

    Separating chart reading and trade logic / dependencies between script

    I would like to separate my bar reading logic from the actual trading logic and put them in different script.

    By doing so, it would allow me to maintain all chart reading variables and logic on 1 place and then use (re-use) it in all my actual strategies.

    It would have to look like this (this is pseudo code, I know there are syntax errors in it)

    Script 1: The chart reading logic

    // define variables
    public double GlobalVar1;
    public double GlobalVar2;

    public void ReadBars()
    {
    GlobalVar1 = Close[0];
    GlobalVar2 = High[0];
    }


    Script 2 (an actual strategy holding trade logic):

    OnBarUpdate()
    {
    ReadBars();
    If (GlobalVar1 > Close[1])
    {
    // do something
    }
    }


    Script 3 (another actual strategy holding trade logic):

    OnBarUpdate()
    {
    ReadBars();
    If (GlobalVar2 > Close[1])
    {
    // do something
    }
    }

    Could anyone help me how to structure this and how to define the dependency between the 2 scripts (e.g. with 'use' or other techniques)

    Many thanks,
    Philip

    #2
    Originally posted by Pvtrade View Post
    I would like to separate my bar reading logic from the actual trading logic and put them in different script.

    By doing so, it would allow me to maintain all chart reading variables and logic on 1 place and then use (re-use) it in all my actual strategies.

    It would have to look like this (this is pseudo code, I know there are syntax errors in it)

    Script 1: The chart reading logic

    // define variables
    public double GlobalVar1;
    public double GlobalVar2;

    public void ReadBars()
    {
    GlobalVar1 = Close[0];
    GlobalVar2 = High[0];
    }


    Script 2 (an actual strategy holding trade logic):

    OnBarUpdate()
    {
    ReadBars();
    If (GlobalVar1 > Close[1])
    {
    // do something
    }
    }


    Script 3 (another actual strategy holding trade logic):

    OnBarUpdate()
    {
    ReadBars();
    If (GlobalVar2 > Close[1])
    {
    // do something
    }
    }

    Could anyone help me how to structure this and how to define the dependency between the 2 scripts (e.g. with 'use' or other techniques)

    Many thanks,
    Philip
    Make "script 1" as a "partial class" of the Strategy class. Then access the methods and variables in the manner that you have already shown.

    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
    2 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