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 Mindset, 04-21-2026, 06:46 AM
0 responses
88 views
0 likes
Last Post Mindset
by Mindset
 
Started by M4ndoo, 04-20-2026, 05:21 PM
0 responses
134 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by M4ndoo, 04-19-2026, 05:54 PM
0 responses
68 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by cmoran13, 04-16-2026, 01:02 PM
0 responses
119 views
0 likes
Last Post cmoran13  
Started by PaulMohn, 04-10-2026, 11:11 AM
0 responses
67 views
0 likes
Last Post PaulMohn  
Working...
X