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 GussJ, 03-04-2020, 03:11 PM
    15 responses
    3,271 views
    0 likes
    Last Post xiinteractive  
    Started by Tim-c, Today, 02:10 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Taddypole, Today, 02:47 PM
    0 responses
    2 views
    0 likes
    Last Post Taddypole  
    Started by chbruno, 04-24-2024, 04:10 PM
    4 responses
    51 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    10 responses
    403 views
    1 like
    Last Post beobast
    by beobast
     
    Working...
    X