Why did I take profit or stop loss?
Why did I take profit or stop loss?
13 Aug 2019, 07:15
this is picture.
I don't understand. You help me about that code. and send a order to a mail.
My Code:
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 CT_PlaceStopOrderLearn : Robot
{
#region User Supplied Parameters
[Parameter("Volume", DefaultValue = 10000)]
public int Volume { get; set; }
[Parameter("Sop Loss (pips)", DefaultValue = 100)]
public int StopLossPips { get; set; }
[Parameter("Take Profit (pips)", DefaultValue = 30)]
public int TakeProfitPips { get; set; }
#endregion
#region cTrader Events
protected override void OnStart()
{
}
protected override void OnTick()
{
// Put your core logic here
}
protected override void OnBar()
{
// Define Bars:
//Define (last FORMING bar) OHLC - think of this as bar 0.
double currOpen = MarketSeries.Open.LastValue;
double currHigh = MarketSeries.High.LastValue;
double currLow = MarketSeries.Low.LastValue;
double currClose = MarketSeries.Close.LastValue;
// Define Bar (last closed bar) OHLC
double Open1 = MarketSeries.Open.Last(1);
double High1 = MarketSeries.High.Last(1);
double Low1 = MarketSeries.Low.Last(1);
double Close1 = MarketSeries.Close.Last(1);
// Define (1 Bars before last closed bar) bar OHLC
double Open2 = MarketSeries.Open.Last(2);
double High2 = MarketSeries.High.Last(2);
double Low2 = MarketSeries.Low.Last(2);
double Close2 = MarketSeries.Close.Last(2);
// Define (2 Bars before last closed) bar OHLC
double Open3 = MarketSeries.Open.Last(3);
double High3 = MarketSeries.High.Last(3);
double Low3 = MarketSeries.Low.Last(3);
double Close3 = MarketSeries.Close.Last(3);
// Define (3 Bars before last closed) bar OHLC
double Open4 = MarketSeries.Open.Last(4);
double High4 = MarketSeries.High.Last(4);
double Low4 = MarketSeries.Low.Last(4);
double Close4 = MarketSeries.Close.Last(4);
if (Close2 > Open2 && Close1 > Open1)
{
PlaceLimitOrder(TradeType.Buy, Symbol, Volume, MarketSeries.Low.Last(1), "b", StopLossPips, TakeProfitPips);
Print("The buylimit is: ", MarketSeries.High.Last(1));
}
else if (Close2 < Open2 && Close1 < Open1)
{
PlaceLimitOrder(TradeType.Sell, Symbol, Volume, MarketSeries.High.Last(1), "s2", StopLossPips, TakeProfitPips);
Print("The selllimit is : ", MarketSeries.High.Last(1));
}
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
#endregion
}
}