EntryPrice Position
EntryPrice Position
04 Jun 2019, 05:17
Good night,
I am trying to get cbot to only enter a certain position, I would like help to solve the problem, thanks in advance.
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 NewcBot : Robot { [Parameter("Buy", DefaultValue = true)] public bool TradeTypeBuy { get; set; } [Parameter(DefaultValue = 1)] public int Volume { get; set; } [Parameter(DefaultValue = "myLabel")] public string cBotLabel { get; set; } [Parameter(DefaultValue = 480)] public double TakeProfitPips { get; set; } [Parameter(DefaultValue = 1500)] public double StopLossPips { get; set; } [Parameter("Posição", DefaultValue = 1300)] public double EntryPrice { get; set; } protected TradeType cBotTradeType { get { return TradeTypeBuy ? TradeType.Buy : TradeType.Sell; } } protected override void OnStart() { Positions.Opened += OnPositionsOpened; Positions.Closed += OnPositionsClosed; ExecuteMarketOrder(cBotTradeType, Symbol, Volume, cBotLabel, StopLossPips, TakeProfitPips, EntryPrice); } protected void OnPositionsOpened(PositionOpenedEventArgs args) { var position = args.Position; if (position.Label == cBotLabel) Print("Position opened by cBot"); } private void OnPositionsClosed(PositionClosedEventArgs args) { var position = args.Position; if (position.Label == cBotLabel) { Print("Position closed by cBot"); ExecuteMarketOrder(cBotTradeType, Symbol, Volume, cBotLabel, StopLossPips, TakeProfitPips); } } } }
Replies
diegorcirelli
04 Jun 2019, 15:25
Good Morning,
So ... Using XAUUSD as an example:
Considering the value of it in 1300, then I open a buying position and closes in 1305, and only open again in 1300 and not in 1305 as it has happened.
@diegorcirelli
PanagiotisCharalampous
04 Jun 2019, 16:24
Hi diegorcirelli,
In this case you will need to place limit orders with the desired price. See below an example
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 NewcBot : Robot { [Parameter("Buy", DefaultValue = true)] public bool TradeTypeBuy { get; set; } [Parameter(DefaultValue = 1)] public int Volume { get; set; } [Parameter(DefaultValue = "myLabel")] public string cBotLabel { get; set; } [Parameter(DefaultValue = 480)] public double TakeProfitPips { get; set; } [Parameter(DefaultValue = 1500)] public double StopLossPips { get; set; } [Parameter("Posição", DefaultValue = 1300)] public double EntryPrice { get; set; } protected TradeType cBotTradeType { get { return TradeTypeBuy ? TradeType.Buy : TradeType.Sell; } } protected override void OnStart() { Positions.Opened += OnPositionsOpened; Positions.Closed += OnPositionsClosed; ExecuteMarketOrder(cBotTradeType, Symbol, Volume, cBotLabel, StopLossPips, TakeProfitPips, EntryPrice); } protected void OnPositionsOpened(PositionOpenedEventArgs args) { var position = args.Position; if (position.Label == cBotLabel) Print("Position opened by cBot"); } private void OnPositionsClosed(PositionClosedEventArgs args) { var position = args.Position; if (position.Label == cBotLabel) { Print("Position closed by cBot"); PlaceLimitOrder(position.TradeType, Symbol, position.VolumeInUnits, position.EntryPrice, cBotLabel, StopLossPips, TakeProfitPips); } } } }
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
04 Jun 2019, 19:54
Good afternoon,
I'm sorry for English, I'm using google's language tool. Let me explain my whole strategy better:
Again considering XAUUSD
In the Instance there will be:
Buy (Yes / No)
Sell (Yes / No)
Pips 100 (1-1000) (Distance from one position and another)
Volume 1 (1-10000)
TakeProfit 480 (1-10000)
StopLoss 1500 (1-10000)
Behavior 1
XAUUSD 1300:
1 Purchase position 1300 (takeprofit 1304.80 / Stoploss 1285)
1 Sales position 1300 (takeprofit 1295.20 / Stoploss 1315)
Behavior 2
XAUUSD 1301
1 Purchase position 1300 (takeprofit 1304.80 / Stoploss 1285)
1 Sales position 1300 (takeprofit 1295.20 / Stoploss 1315)
1 Purchase position 1301 (takeprofit 1305.80 / Stoploss 1286)
1 Sales position 1301 (takeprofit 1296.20 / Stoploss 1316)
Behavior 3
XAUUSD 1302
1 Purchase position 1300 (takeprofit 1304.80 / Stoploss 1285)
1 Sales position 1300 (takeprofit 1296.20 / Stoploss 1315)
1 Purchase position 1301 (takeprofit 1305.80 / Stoploss 1286)
1 Sales position 1301 (takeprofit 1297.20 / Stoploss 1316)
1 Purchase position 1302 (takeprofit 1306.80 / Stoploss 1287)
1 Sales position 1302 (takeprofit 1298.20 / Stoploss 1317)
Behavior 4
XAUUSD 1303
1 Purchase position 1300 (takeprofit 1304.80 / Stoploss 1285)
1 Sales position 1300 (takeprofit 1295.20 / Stoploss 1315)
1 Purchase position 1301 (takeprofit 1305.80 / Stoploss 1286)
1 Sales position 1301 (takeprofit 1296.20 / Stoploss 1316)
1 Purchase position 1302 (takeprofit 1306.80 / Stoploss 1287)
1 Sales position 1302 (takeprofit 1297.20 / Stoploss 1317)
1 Purchase position 1303 (takeprofit 1307.80 / Stoploss 1288)
1 Sales position 1303 (takeprofit 1298.20 / Stoploss 1318)
Behavior 5
XAUUSD 1304
1 Purchase position 1300 (takeprofit 1304.80 / Stoploss 1285)
1 Sales position 1300 (takeprofit 1295.20 / Stoploss 1315)
1 Purchase position 1301 (takeprofit 1305.80 / Stoploss 1286)
1 Sales position 1301 (takeprofit 1296.20 / Stoploss 1316)
1 Purchase position 1302 (takeprofit 1306.80 / Stoploss 1287)
1 Sales position 1302 (takeprofit 1297.20 / Stoploss 1317)
1 Purchase position 1303 (takeprofit 1307.80 / Stoploss 1288)
1 Sales position 1303 (takeprofit 1298.20 / Stoploss 1318)
1 Purchase position 1304 (takeprofit 1308.80 / Stoploss 1289)
1 Sales position 1304 (takeprofit 1299.20 / Stoploss 1319)
Behavior 6
XAUUSD 1305
Closing * 1 Purchase position 1300 (takeprofit 1304.80 / Stoploss 1285)
1 Sales position 1300 (takeprofit 1295.20 / Stoploss 1315)
1 Purchase position 1301 (takeprofit 1305.80 / Stoploss 1286)
1 Sales position 1301 (takeprofit 1296.20 / Stoploss 1316)
1 Purchase position 1302 (takeprofit 1306.80 / Stoploss 1287)
1 Sales position 1302 (takeprofit 1297.20 / Stoploss 1317)
1 Purchase position 1303 (takeprofit 1307.80 / Stoploss 1288)
1 Sales position 1303 (takeprofit 1298.20 / Stoploss 1318)
1 Purchase position 1304 (takeprofit 1308.80 / Stoploss 1289)
1 Sales position 1304 (takeprofit 1299.20 / Stoploss 1319)
1 Purchase position 1305 (takeprofit 1309.80 / Stoploss 1290)
1 Sales position 1305 (takeprofit 1300.20 / Stoploss 1320)
Behavior 6
XAUUSD 1302 (Do not pick up position already exists of approximate value)
1 Sales position 1300 (takeprofit 1295.20 / Stoploss 1315)
1 Purchase position 1301 (takeprofit 1305.80 / Stoploss 1286)
1 Sales position 1301 (takeprofit 1296.20 / Stoploss 1316)
1 Purchase position 1302 (takeprofit 1306.80 / Stoploss 1287)
1 Sales position 1302 (takeprofit 1297.20 / Stoploss 1317)
1 Purchase position 1303 (takeprofit 1307.80 / Stoploss 1288)
1 Sales position 1303 (takeprofit 1298.20 / Stoploss 1318)
1 Purchase position 1304 (takeprofit 1308.80 / Stoploss 1289)
1 Sales position 1304 (takeprofit 1299.20 / Stoploss 1319)
1 Purchase position 1305 (takeprofit 1309.80 / Stoploss 1290)
1 Sales position 1305 (takeprofit 1300.20 / Stoploss 1320)
@diegorcirelli
PanagiotisCharalampous
05 Jun 2019, 09:25
Hi diegorcirelli,
If you are looking for somebody to implement your strategy, you can contact a Consultant or post a Job.
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
05 Jun 2019, 15:28
Good Morning...
Okay, thank you, I had searched and did not find it.
@diegorcirelli
diegorcirelli
05 Jun 2019, 19:01
Good afternoon, you can give me one last help, in this code I was able to put Stoploss in the parameters, but the positions are entering without StopLoss defined in this parameter
using System; using System.Linq; using cAlgo.API; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class SmartGrid : Robot { [Parameter("Buy", DefaultValue = true)] public bool Buy { get; set; } [Parameter("Sell", DefaultValue = true)] public bool Sell { get; set; } [Parameter("Pip Step", DefaultValue = 10, MinValue = 1)] public int PipStep { get; set; } [Parameter("First Volume", DefaultValue = 1000, MinValue = 1, Step = 1000)] public int FirstVolume { get; set; } [Parameter("Volume Exponent", DefaultValue = 1.0, MinValue = 0.1, MaxValue = 5.0)] public double VolumeExponent { get; set; } [Parameter("Max Spread", DefaultValue = 3.0)] public double MaxSpread { get; set; } [Parameter("Average TP", DefaultValue = 3, MinValue = 1)] public int AverageTP { get; set; } [Parameter("StopLoss", DefaultValue = 3000, MinValue = 1)] public int StopLoss { get; set; } private string Label = "cls"; private Position position; private DateTime tc_31; private DateTime tc_32; private int gi_21; private double sp_d; private bool is_12 = true; private bool cStop = false; protected override void OnStart() { } protected override void OnTick() { sp_d = (Symbol.Ask - Symbol.Bid) / Symbol.PipSize; if (o_tm(TradeType.Buy) > 0) f0_86(pnt_12(TradeType.Buy), AverageTP); if (o_tm(TradeType.Sell) > 0) f0_88(pnt_12(TradeType.Sell), AverageTP); if (MaxSpread >= sp_d && !cStop) Open_24(); RCN(); } protected override void OnError(Error error) { if (error.Code == ErrorCode.NoMoney) { cStop = true; Print("openning stopped because: not enough money"); } } protected override void OnBar() { RefreshData(); } protected override void OnStop() { ChartObjects.RemoveAllObjects(); } private void Open_24() { if (is_12) { if (Buy && o_tm(TradeType.Buy) == 0 && MarketSeries.Close.Last(1) > MarketSeries.Close.Last(2)) { gi_21 = OrderSend(TradeType.Buy, fer(FirstVolume, 0)); if (gi_21 > 0) tc_31 = MarketSeries.OpenTime.Last(0); else Print("First BUY openning error at: ", Symbol.Ask, "Error Type: ", LastResult.Error); } if (Sell && o_tm(TradeType.Sell) == 0 && MarketSeries.Close.Last(2) > MarketSeries.Close.Last(1)) { gi_21 = OrderSend(TradeType.Sell, fer(FirstVolume, 0)); if (gi_21 > 0) tc_32 = MarketSeries.OpenTime.Last(0); else Print("First SELL openning error at: ", Symbol.Bid, "Error Type: ", LastResult.Error); } } N_28(); } private void N_28() { if (o_tm(TradeType.Buy) > 0) { if (Math.Round(Symbol.Ask, Symbol.Digits) < Math.Round(D_TD(TradeType.Buy) - PipStep * Symbol.PipSize, Symbol.Digits) && tc_31 != MarketSeries.OpenTime.Last(0)) { long gl_57 = n_lt(TradeType.Buy); gi_21 = OrderSend(TradeType.Buy, fer(gl_57, 2)); if (gi_21 > 0) tc_31 = MarketSeries.OpenTime.Last(0); else Print("Next BUY openning error at: ", Symbol.Ask, "Error Type: ", LastResult.Error); } } if (o_tm(TradeType.Sell) > 0) { if (Math.Round(Symbol.Bid, Symbol.Digits) > Math.Round(U_TD(TradeType.Sell) + PipStep * Symbol.PipSize, Symbol.Digits)) { long gl_59 = n_lt(TradeType.Sell); gi_21 = OrderSend(TradeType.Sell, fer(gl_59, 2)); if (gi_21 > 0) tc_32 = MarketSeries.OpenTime.Last(0); else Print("Next SELL openning error at: ", Symbol.Bid, "Error Type: ", LastResult.Error); } } } private int OrderSend(TradeType TrdTp, long iVol) { int cd_8 = 0; if (iVol > 0) { TradeResult result = ExecuteMarketOrder(TrdTp, Symbol, iVol, Label, 0, 0, 0, "smart_grid"); if (result.IsSuccessful) { Print(TrdTp, "Opened at: ", result.Position.EntryPrice); cd_8 = 1; } else Print(TrdTp, "Openning Error: ", result.Error); } else Print("Volume calculation error: Calculated Volume is: ", iVol); return cd_8; } private void f0_86(double ai_4, int ad_8) { foreach (var position in Positions) { if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == TradeType.Buy) { double? li_16 = Math.Round(ai_4 + ad_8 * Symbol.PipSize, Symbol.Digits); if (position.TakeProfit != li_16) ModifyPosition(position, position.StopLoss, li_16); } } } } private void f0_88(double ai_4, int ad_8) { foreach (var position in Positions) { if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == TradeType.Sell) { double? li_16 = Math.Round(ai_4 - ad_8 * Symbol.PipSize, Symbol.Digits); if (position.TakeProfit != li_16) ModifyPosition(position, position.StopLoss, li_16); } } } } private void RCN() { if (o_tm(TradeType.Buy) > 1) { double y = pnt_12(TradeType.Buy); ChartObjects.DrawHorizontalLine("bpoint", y, Colors.Yellow, 2, LineStyle.Dots); } else ChartObjects.RemoveObject("bpoint"); if (o_tm(TradeType.Sell) > 1) { double z = pnt_12(TradeType.Sell); ChartObjects.DrawHorizontalLine("spoint", z, Colors.HotPink, 2, LineStyle.Dots); } else ChartObjects.RemoveObject("spoint"); ChartObjects.DrawText("pan", A_cmt_calc(), StaticPosition.TopLeft, Colors.Tomato); } private string A_cmt_calc() { string gc_78 = ""; string wn_7 = ""; string wn_8 = ""; string sp_4 = ""; string ppb = ""; string lpb = ""; string nb_6 = ""; double dn_7 = 0; double dn_9 = 0; sp_4 = "\nSpread = " + Math.Round(sp_d, 1); nb_6 = "\nwww.facebook.com/cls.fx\n"; if (dn_7 > 0) wn_7 = "\nBuy Positions = " + o_tm(TradeType.Buy); if (dn_9 > 0) wn_8 = "\nSell Positions = " + o_tm(TradeType.Sell); if (o_tm(TradeType.Buy) > 0) { double igl = Math.Round((pnt_12(TradeType.Buy) - Symbol.Bid) / Symbol.PipSize, 1); ppb = "\nBuy Target Away = " + igl; } if (o_tm(TradeType.Sell) > 0) { double osl = Math.Round((Symbol.Ask - pnt_12(TradeType.Sell)) / Symbol.PipSize, 1); lpb = "\nSell Target Away = " + osl; } if (sp_d > MaxSpread) gc_78 = "MAX SPREAD EXCEED"; else gc_78 = "Smart Grid" + nb_6 + wn_7 + sp_4 + wn_8 + ppb + lpb; return (gc_78); } private int cnt_16() { int ASide = 0; for (int i = Positions.Count - 1; i >= 0; i--) { position = Positions[i]; if (position.Label == Label && position.SymbolCode == Symbol.Code) ASide++; } return ASide; } private int o_tm(TradeType TrdTp) { int TSide = 0; for (int i = Positions.Count - 1; i >= 0; i--) { position = Positions[i]; if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == TrdTp) TSide++; } } return TSide; } private double pnt_12(TradeType TrdTp) { double Result = 0; double AveragePrice = 0; long Count = 0; for (int i = Positions.Count - 1; i >= 0; i--) { position = Positions[i]; if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == TrdTp) { AveragePrice += position.EntryPrice * position.Volume; Count += position.Volume; } } } if (AveragePrice > 0 && Count > 0) Result = Math.Round(AveragePrice / Count, Symbol.Digits); return Result; } private double D_TD(TradeType TrdTp) { double D_TD = 0; for (int i = Positions.Count - 1; i >= 0; i--) { position = Positions[i]; if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == TrdTp) { if (D_TD == 0) { D_TD = position.EntryPrice; continue; } if (position.EntryPrice < D_TD) D_TD = position.EntryPrice; } } } return D_TD; } private double U_TD(TradeType TrdTp) { double U_TD = 0; for (int i = Positions.Count - 1; i >= 0; i--) { position = Positions[i]; if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == TrdTp) { if (U_TD == 0) { U_TD = position.EntryPrice; continue; } if (position.EntryPrice > U_TD) U_TD = position.EntryPrice; } } } return U_TD; } private double f_tk(TradeType TrdTp) { double prc_4 = 0; int tk_4 = 0; for (int i = Positions.Count - 1; i >= 0; i--) { position = Positions[i]; if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == TrdTp) { if (tk_4 == 0 || tk_4 > position.Id) { prc_4 = position.EntryPrice; tk_4 = position.Id; } } } } return prc_4; } private long lt_8(TradeType TrdTp) { long lot_4 = 0; int tk_4 = 0; for (int i = Positions.Count - 1; i >= 0; i--) { position = Positions[i]; if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == TrdTp) { if (tk_4 == 0 || tk_4 > position.Id) { lot_4 = position.Volume; tk_4 = position.Id; } } } } return lot_4; } private long clt(TradeType TrdTp) { long Result = 0; for (int i = Positions.Count - 1; i >= 0; i--) { position = Positions[i]; if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == TrdTp) Result += position.Volume; } } return Result; } private int Grd_Ex(TradeType ai_0, TradeType ci_0) { double prc_4 = f_tk(ci_0); int tk_4 = 0; for (int i = Positions.Count - 1; i >= 0; i--) { position = Positions[i]; if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == ai_0 && ai_0 == TradeType.Buy) { if (Math.Round(position.EntryPrice, Symbol.Digits) <= Math.Round(prc_4, Symbol.Digits)) tk_4++; } if (position.TradeType == ai_0 && ai_0 == TradeType.Sell) { if (Math.Round(position.EntryPrice, Symbol.Digits) >= Math.Round(prc_4, Symbol.Digits)) tk_4++; } } } return (tk_4); } private long n_lt(TradeType ca_8) { int ic_g = Grd_Ex(ca_8, ca_8); long gi_c = lt_8(ca_8); long ld_4 = Symbol.NormalizeVolume(gi_c * Math.Pow(VolumeExponent, ic_g)); return (ld_4); } private long fer(long ic_9, int bk_4) { long ga_i = Symbol.VolumeMin; long gd_i = Symbol.VolumeStep; long dc_i = Symbol.VolumeMax; long ic_8 = ic_9; if (ic_8 < ga_i) ic_8 = ga_i; if (ic_8 > dc_i) ic_8 = dc_i; return (ic_8); } } }
@diegorcirelli
diegorcirelli
10 Jun 2019, 19:56
Good afternoon... I'm trying to do my project and something is not working, could you help me, code follows.
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 MeuMesmo : Robot { [Parameter("Volume", DefaultValue = 0)] public double Vol { get; set; } [Parameter("StopLoss", DefaultValue = 0)] public double SL { get; set; } [Parameter("TakeProfit", DefaultValue = 0)] public double TP { get; set; } [Parameter(DefaultValue = 0)] public double Pips { get; set; } private readonly string Label = "MeuMesmo"; private double FindLowestPositionPrice(TradeType tradeType) { double lowestPriceBuy = 0; foreach (var position in Positions) { if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == tradeType) { if (lowestPriceBuy == 0) { lowestPriceBuy = position.EntryPrice; continue; } if (position.EntryPrice < lowestPriceBuy) lowestPriceBuy = position.EntryPrice; } } } return lowestPriceBuy; } private double FindHighestPositionPrice(TradeType tradeType) { double highestPriceBuy = 0; foreach (var position in Positions) { if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == tradeType) { if (highestPriceBuy == 0) { highestPriceBuy = position.EntryPrice; continue; } if (position.EntryPrice > highestPriceBuy) highestPriceBuy = position.EntryPrice; } } } return highestPriceBuy; } protected override void OnStart() { } protected override void OnTick() { if (highestPriceBuy + Pips < Symbol.Bid) ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); if (lowestPriceBuy - Pips < Symbol.Bid) ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); } protected override void OnStop() { // Put your deinitialization logic here } } }
@diegorcirelli
PanagiotisCharalampous
11 Jun 2019, 09:24
Hi diegorcirelli,
What is not working?
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
11 Jun 2019, 13:18
Good Morning... I would like you to return the position with the biggest entryprice. Example I have positions 1010 1005 1000 I would like you to return the 1010
private double FindHighestPositionPrice(TradeType tradeType) { double highestPriceBuy = 0; foreach (var position in Positions) { if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (position.TradeType == tradeType) { if (highestPriceBuy == 0) { highestPriceBuy = position.EntryPrice; continue; } if (position.EntryPrice > highestPriceBuy) highestPriceBuy = position.EntryPrice; } } } return highestPriceBuy; }
@diegorcirelli
diegorcirelli
12 Jun 2019, 01:24
Good evening ... now a little developed this code, but also did not work, could you help me ??
protected override void OnTick() { var highestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.EntryPrice); if (highestPriceBuy + Pips <= Symbol.Bid) ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); }
@diegorcirelli
PanagiotisCharalampous
12 Jun 2019, 10:26
RE:
diegorcirelli said:
Good evening ... now a little developed this code, but also did not work, could you help me ??
protected override void OnTick() { var highestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.EntryPrice); if (highestPriceBuy + Pips <= Symbol.Bid) ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); }
Hi diegorcirelli,
I do not see any problem in this code. Can you please explain to us why you think it is not working? What do you expect it to do and what does it do instead?
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
12 Jun 2019, 14:32
Good morning then...
It is not running ... the idea is that when symbol.bid is "x" pips above the largest existing position, it executes the order ...
Example:
Existing positions
1010
1005
1000
Using 5 pips, when the highest position (which is 1010) added to the pips (which is 5) is less than or equal to symbol.bid, it should run.
But it is not running, it does nothing.
@diegorcirelli
PanagiotisCharalampous
12 Jun 2019, 14:36
Hi diegorcirelli,
Can you provide enough information to reproduce what you are seeing? We need
- The full cBot code
- Backtesting parameters
- Date and time where you would expect the trade to happed but does not.
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
12 Jun 2019, 14:47
( Updated at: 21 Dec 2023, 09:21 )
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 MeuMesmo : Robot { [Parameter("Volume", DefaultValue = 1)] public double Vol { get; set; } [Parameter("StopLoss", DefaultValue = 1000)] public double SL { get; set; } [Parameter("TakeProfit", DefaultValue = 100)] public double TP { get; set; } [Parameter("Distância", DefaultValue = 100)] public double Pips { get; set; } private readonly string Label = "MeuMesmo"; protected override void OnStart() { } protected override void OnTick() { var highestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.EntryPrice); if (highestPriceBuy + Pips <= Symbol.Bid) ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); var lowestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Min(x => x.EntryPrice); if (lowestPriceBuy - Pips <= Symbol.Bid) ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); } protected override void OnStop() { // Put your deinitialization logic here } } }
@diegorcirelli
PanagiotisCharalampous
12 Jun 2019, 15:00
Ηι diegorcirelli,
If you run the cBot as is, it will not do anything as there are no open positions in the first place. When the cBot starts, from which position do you expect it to measure the distance since there is none open?
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
12 Jun 2019, 15:07
( Updated at: 21 Dec 2023, 09:21 )
I already did this test and also did not work, he buys several ...
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 MeuMesmo : Robot { [Parameter("Volume", DefaultValue = 1)] public double Vol { get; set; } [Parameter("StopLoss", DefaultValue = 1000)] public double SL { get; set; } [Parameter("TakeProfit", DefaultValue = 100)] public double TP { get; set; } [Parameter("Distância", DefaultValue = 100)] public double Pips { get; set; } private readonly string Label = "MeuMesmo"; protected override void OnStart() { ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); } protected override void OnTick() { var highestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.EntryPrice); if (highestPriceBuy + Pips <= Symbol.Bid) ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); var lowestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Min(x => x.EntryPrice); if (lowestPriceBuy - Pips <= Symbol.Bid) ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); } protected override void OnStop() { // Put your deinitialization logic here } } }
@diegorcirelli
PanagiotisCharalampous
12 Jun 2019, 15:16
Hi diegorcirelli,
Here is an attempt to guess what you are trying to do
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 MeuMesmo : Robot { [Parameter("Volume", DefaultValue = 1)] public double Vol { get; set; } [Parameter("StopLoss", DefaultValue = 1000)] public double SL { get; set; } [Parameter("TakeProfit", DefaultValue = 100)] public double TP { get; set; } [Parameter("Distância", DefaultValue = 100)] public double Pips { get; set; } private readonly string Label = "MeuMesmo"; protected override void OnStart() { ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); } protected override void OnTick() { if (Positions.Count > 0) { var highestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.EntryPrice); if (highestPriceBuy + (Symbol.PipValue * Pips) <= Symbol.Bid) ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); var lowestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Min(x => x.EntryPrice); if (lowestPriceBuy - (Symbol.PipValue * Pips) >= Symbol.Bid) ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); } } protected override void OnStop() { // Put your deinitialization logic here } } }
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
12 Jun 2019, 15:50
Excellent ... It worked ...
I'll do some tests and comeback if there are more problems ...
@diegorcirelli
diegorcirelli
12 Jun 2019, 15:55
Could it be configured to count only the purchase positions ??
@diegorcirelli
PanagiotisCharalampous
12 Jun 2019, 16:00
Hi,
Here is a more correct condition
if (Positions.Count(x => x.SymbolCode == Symbol.Code && x.Label == Label && x.TradeType == TradeType.Buy) > 0)
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
13 Jun 2019, 00:42
Good night my friend...
I did the proper tests and really for the purpose it worked. And before testing I would like to add a code to modify the Position Volume when it reaches a certain distance from the current value, it follows the "faulty" code, thank you again if you can help me.
[Parameter("Média", DefaultValue = 1000)] public double Average { get; set; } var AverageBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.EntryPrice); if (AverageBuy - (Symbol.PipValue * Average) <= Symbol.Bid) ModifyPosition(AverageBuy, (Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.VolumeInUnits)) * 2, TP);
@diegorcirelli
PanagiotisCharalampous
13 Jun 2019, 09:52
Hi diegorcirelli,
If you need assistance in developing your cBot, I would advise you to contact a Consultant or post a Job.
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
13 Jun 2019, 14:13
Good morning ... yesterday I did the tests only in XAUUSD and worked as expected, however when testing in EURUSD, GBPUSD and others, nothing happened, can you tell me what could be wrong in the code ??
@diegorcirelli
PanagiotisCharalampous
13 Jun 2019, 14:22
Hi diegorcirelli,
I just tried it and it works. I don't see anything wrong.
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
13 Jun 2019, 14:59
( Updated at: 21 Dec 2023, 09:21 )
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 MeuMesmo : Robot { [Parameter("Volume", DefaultValue = 1)] public double Vol { get; set; } [Parameter("StopLoss", DefaultValue = 1000)] public double SL { get; set; } [Parameter("TakeProfit", DefaultValue = 100)] public double TP { get; set; } [Parameter("Distância", DefaultValue = 100)] public double Pips { get; set; } private readonly string Label = "MeuMesmo"; protected override void OnStart() { ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); } protected override void OnBar() { if (Positions.Count(x => x.SymbolCode == Symbol.Code && x.Label == Label && x.TradeType == TradeType.Buy) > 0) { var highestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Max(x => x.EntryPrice); if (highestPriceBuy + (Symbol.PipValue * Pips) <= Symbol.Bid) ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); var lowestPriceBuy = Positions.FindAll(Label, Symbol, TradeType.Buy).Min(x => x.EntryPrice); if (lowestPriceBuy - (Symbol.PipValue * Pips) >= Symbol.Bid) ExecuteMarketOrder(TradeType.Buy, Symbol, Vol, Label, SL, TP); } } protected override void OnStop() { // Put your deinitialization logic here } } }
@diegorcirelli
PanagiotisCharalampous
13 Jun 2019, 15:01
Hi diegorcirelli,
Check your volume. The mimimum for EURUSD is 1000.
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
14 Jun 2019, 13:52
Good Morning,
I have a problem that I can not solve.
How I wish the strategy worked:
TP = 1 Average = 20
Symbol = 1000 open Position 1 = Volume 1.00 / EntryPrice 1000 / TP 1001
Symbol = 980 Modify Position 1 = Volume 2.00 / EntryPrice 990 ((1000 + 980) / 2) / TP 991
Okay
How is he working?
Symbol = 1000 open Position 1 = Volume 1.00 / EntryPrice 1000 / TP 1001
Symbol = 980 Modify Position 1 = Volume 2.00 / EntryPrice 990 ((1000 + 980) / 2) / TP 1001
I added in the Modify TP the formula ((Average / 2) + TP)
So he works as follows
Symbol = 1000 open Position 1 = Volume 1.00 / EntryPrice 1000 / TP 1001
Symbol = 980 Modify Position 1 = Volume 1.00 / EntryPrice 1000 / TP 996 & Volume 1.00 / EntryPrice 980 / TP 981
I'm not sure how to solve it, could you help me?
foreach (var position in Positions) { if (position.TradeType == TradeType.Buy && position.EntryPrice > Symbol.Bid + (Symbol.PipValue * Average)) { ModifyPosition(position, position.VolumeInUnits * (1 + Exp)); } }
foreach (var position in Positions) { if (position.TradeType == TradeType.Buy && position.EntryPrice > Symbol.Bid + (Symbol.PipValue * Average)) { ModifyPosition(position, position.VolumeInUnits * (1 + Exp), (Average/2)+TP); } }
@diegorcirelli
diegorcirelli
14 Jun 2019, 23:33
Good afternoon...
I was able ... I wonder if it is possible to simulate monthly, weekly or even daily withdrawal, just for testing.
@diegorcirelli
PanagiotisCharalampous
18 Jun 2019, 11:49
Hi diegorcirelli,
Simulating deposits and withdrawals is not possible at the moment.
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
19 Jun 2019, 16:00
( Updated at: 21 Dec 2023, 09:21 )
Good Morning, I'm having a problem at the margin, it's out of the real, print follows.
@diegorcirelli
diegorcirelli
25 Jun 2019, 19:33
( Updated at: 21 Dec 2023, 09:21 )
Good afternoon ... The Margin is totally out of the picture, is there anything I can do to fix it ?? Apparently it occurs when I make a change in position.
@diegorcirelli
PanagiotisCharalampous
26 Jun 2019, 09:31
Hi diegorcirelli,
Can you please post a screenshot of the entire interface so that we can understand where did you get this screenshot from? Also I am not sure what do you mean that margin is out of the picture. I can see it.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
26 Jun 2019, 15:16
Hi diegorcirelli,
It is still not clear to me what is the problem.
Best Regards,
Panagiotis
@PanagiotisCharalampous
diegorcirelli
26 Jun 2019, 15:36
I have a total of 560Oz purchase positions and 570Oz in sales positions, using $ 3991 of Margin, and my capital added to the net profit does not even come close to this value ... That is, it is opening new positions that in a real account will be impossible to open.
@diegorcirelli
PanagiotisCharalampous
26 Jun 2019, 15:50
Hi diegorcirelli,
At the moment margin requirements are not taken into consideration by cTrader Automate and the backtesting process
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
04 Jun 2019, 09:49
Hi diegorcirelli,
Thank you for posting in our forum. However it is not clear from your post what is the problem you are trying to solve. Could you please try explaining it in more detail?
Best Regards,
Panagiotis
@PanagiotisCharalampous