Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom indicator + Strategy with multiple instruments

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

    Custom indicator + Strategy with multiple instruments

    Hi,
    I created a strategy based on a custom indicator and when I run the "strategy analyser", it returns 0 trades... I think there is a problem in my strategy but I can't find what is wrong (I'm a beginner...).

    My indicator is working properly, when I put it on a chart it returns me the right results (attached is a screenshot of my indicator). This indicator is not based on the instrument of the chart you put it on. It is an indicator that uses 2 additional dataseries and it is calculated only on these 2 additional dataseries (it does not use the dataseries of the chart, we can put it on any instrument chart it will display the same thing).

    Then, in my strategy, depending on the value of this indicator, I have to enter long on one instrument and short on another instrument. So I added 2 dataseries to my strategy to ignore the main instrument (as for my indicator).

    In "public class" of my strategy, I called my indicator:
    public class MyStrat : Strategy
    {
    private MyIndicator indic;





    Then in State.Configure, I added the dataseries:
    AddDataSeries("MNQ 12-22", BarsArray[0].BarsPeriod);
    AddDataSeries("MES 12-22", BarsArray[0].BarsPeriod);





    Then in State.Dataloaded, I loaded my indicator:

    indic = MyIndicator();
    AddChartIndicator(indic);





    And finally in OnBarUpdate(), I added conditions to enter on the 2 instruments:
    protected override void OnBarUpdate()
    {
    indicateur.Update();

    if(indic[0] > 20)
    {
    if(BarsInProgress == 1)
    {
    EnterShort(2);
    }
    if(BarsInProgress == 2)
    {
    EnterLong(3);
    }
    }




    With this, if my indicator exceeds 20, I am supposed to enter short on MNQ with quantity 2 and long on MES with quantity 3.

    For position exits, I use this:
    protected override void OnAccountItemUpdate(Account account, AccountItem accountItem, double value)
    {
    if(PositionAccount.GetUnrealizedProfitLoss(Perform anceUnit.Currency) > 25)
    {
    Account.Flatten(new[] {Instrument.GetInstrument("MNQ 12-22") });
    Account.Flatten(new[] {Instrument.GetInstrument("MES 12-22") });
    }
    }




    The goal is to close all positions if I have an unrealized profit of $25.

    When I run the strategy in the strategy analyzer it returns me no trade... I don't understand where I made a mistake...
    Thanks in advance

    EDIT: I tried to run the strategy on playback account on there is no entry... And when i put the strategy on a graphic instrument, the indicator is not displayed (although i put "AddChartIndicator"). I think my strategy can't access the indicator but I don't know why...
    Attached Files
    Last edited by jiyu.invest; 10-23-2022, 10:11 AM.

Latest Posts

Collapse

Topics Statistics Last Post
Started by NullPointStrategies, Yesterday, 05:17 AM
0 responses
64 views
0 likes
Last Post NullPointStrategies  
Started by argusthome, 03-08-2026, 10:06 AM
0 responses
139 views
0 likes
Last Post argusthome  
Started by NabilKhattabi, 03-06-2026, 11:18 AM
0 responses
75 views
0 likes
Last Post NabilKhattabi  
Started by Deep42, 03-06-2026, 12:28 AM
0 responses
45 views
0 likes
Last Post Deep42
by Deep42
 
Started by TheRealMorford, 03-05-2026, 06:15 PM
0 responses
50 views
0 likes
Last Post TheRealMorford  
Working...
X