Announcement

Collapse
No announcement yet.

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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    133 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    75 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    117 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    113 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    90 views
    0 likes
    Last Post CarlTrading  
    Working...
    X