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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    52 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    142 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    276 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X