Sample RSI - How do you enter the Stop Loss ?!
Sample RSI - How do you enter the Stop Loss ?!
09 Dec 2018, 17:24
// ------------------------------------------------------------------------------------------------- // // This code is a cAlgo API sample. // // This robot is intended to be used as a sample and does not guarantee any particular outcome or // profit of any kind. Use it at your own risk. // // All changes to this file will be lost on next application start. // If you are going to modify this file please make a copy using the "Duplicate" command. // // The "Sample RSI Range Robot" will create a buy order when the Relative Strength Index indicator crosses the level 30, // and a Sell order when the RSI indicator crosses the level 70. The order is closed be either a Stop Loss, defined in // the "Stop Loss" parameter, or by the opposite RSI crossing signal (buy orders close when RSI crosses the 70 level // and sell orders are closed when RSI crosses the 30 level). // // The robot can generate only one Buy or Sell order at any given time. // // ------------------------------------------------------------------------------------------------- using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class SampleRSIRobot : Robot { [Parameter("Source")] public DataSeries Source { get; set; } [Parameter("Periods", DefaultValue = 14)] public int Periods { get; set; } [Parameter("Stop Loss (pips)", DefaultValue = 10, MinValue = 1)] public int StopLoss { get; set; } [Parameter("Volume", DefaultValue = 10000, MinValue = 1000)] public int Volume { get; set; } private RelativeStrengthIndex rsi; protected override void OnStart() { rsi = Indicators.RelativeStrengthIndex(Source, Periods); } protected override void OnTick() { if (rsi.Result.LastValue < 30) { Close(TradeType.Sell); Open(TradeType.Buy); } else if (rsi.Result.LastValue > 70) { Close(TradeType.Buy); Open(TradeType.Sell); } } private void Close(TradeType tradeType) { foreach (var position in Positions.FindAll("SampleRSI", Symbol, tradeType)) ClosePosition(position); } private void Open(TradeType tradeType) { var position = Positions.Find("SampleRSI", Symbol, tradeType); if (position == null) ExecuteMarketOrder(tradeType, Symbol, Volume, "SampleRSI"); } } }
https://ctrader.com/algos/cbots/show/403
SL how active ?!
Gretting.
Replies
seibertm
12 Jan 2019, 11:16
Sample RSI Stop Loss
Hi, I tried the suggested change to the code, and the code fails with these messages:
Argument 4: cannot convert from 'method group' to 'string'
The best overloaded method match for 'cAlgo.API.Robot.ExecuteMarketOrder(cAlgo.API.TradeType, cAlgo.API.Internals.Symbol, long, string, double?, double?)' has some invalid arguments
I'm a newbie with Algo coding and can not figure out how I could fix this. Any help?
@seibertm
PanagiotisCharalampous
14 Jan 2019, 10:38
Hi seibert,
It seems there is a typo.The correct command is below
ExecuteMarketOrder(tradeType, Symbol, Volume, "SampleRSI", StopLoss, null);
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
10 Dec 2018, 11:00
Hi tgjobscv,
Change line 76 to the following
Best Regards,
Panagiotis
@PanagiotisCharalampous