Programmers please help me with this

Created at 23 Nov 2023, 13:09
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
KI

kippod

Joined 23.11.2023

Programmers please help me with this
23 Nov 2023, 13:09


Programmers please help me with this issue. I just know there is nothing impossible in programming.😁
In the picture below, I've used the fractal indicator, all I want is the Previous fractal (not the last). How can I call it??!

 

when I use the (UpFractalS.LastValue)  gives me the correct last up fractal , but when I use the (UpFractalS.Last(1)) it doesn't work right.

I want this for my robot. thanks a lot

 


@kippod
Replies

firemyst
25 Nov 2023, 09:24

_

Can you post example code and example output that demonstrates your issue?


@firemyst

firemyst
25 Nov 2023, 09:24

__

Can you post example code and example output that demonstrates your issue?


@firemyst

kippod
02 Dec 2023, 13:23 ( Updated at: 04 Dec 2023, 08:32 )

RE: _

firemyst said: 

Can you post example code and example output that demonstrates your issue?

Hi firemyst
Thank you for your time. 

Actually I don't get any error it just doesn't work

here's the code

(This is not my bot, it just shows you the problem)

 using cAlgo.API;
 using cAlgo.API.Indicators;
 using cAlgo.API.Internals;
 namespace cAlgo.Robots
 {

     [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class FractalsSample : Robot
     {
         private double _volumeInUnits;
         private Fractals _fractals;
         [Parameter("Volume (Lots)", DefaultValue = 0.01)]
         public double VolumeInLots { get; set; }
         [Parameter("Stop Loss (Pips)", DefaultValue = 10)]
         public double StopLossInPips { get; set; }
         [Parameter("Take Profit (Pips)", DefaultValue = 10)]
         public double TakeProfitInPips { get; set; }
         [Parameter("Label", DefaultValue = "Sample")]
         public string Label { get; set; }
         public Position[] BotPositions
         {
             get
             {
                 return Positions.FindAll(Label);
             }
         }
         protected override void OnStart()
         {
             _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
             _fractals = Indicators.Fractals(5);
         }
         protected override void OnBar()
         {
             if (_fractals.UpFractal.LastValue < Bars.ClosePrices.Last(1))
             {
                 ClosePositions(TradeType.Sell);
                 ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
             }
             else if (_fractals.DownFractal.LastValue > Bars.ClosePrices.Last(1))
             {
                 ClosePositions(TradeType.Buy);
                 ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
             }
         }
         private void ClosePositions(TradeType tradeType)
         {
             foreach (var position in BotPositions)
             {
                 if (position.TradeType != tradeType) continue;
                 ClosePosition(position);
             }
         }
     }
 }
// i just want to call previous fractals


@kippod