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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    647 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    368 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    571 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X