Topics
Replies
anjupeguforex@gmail.com
12 Oct 2017, 13:12
RE:
Panagiotis Charalampous said:
Hi anjupeguforex@gmail.com,
You get this exception because you are trying to access an array item that does not exist. Before accessing a position in Positions using index You should always check that the index is within the range of the array. I propose to change checks like the following
if (poz[1] != null)to
if (poz.Length > 1)Best Regards,
Panagiotis
Now all are working.Thank You very much.
@anjupeguforex@gmail.com
anjupeguforex@gmail.com
12 Oct 2017, 07:23
Same issue Again
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class FXGODREWORKING : Robot
{
[Parameter("Position Volume", DefaultValue = 1000, MinValue = 1000, Step = 5000)]
public int InitialVolume { get; set; }
[Parameter("Buy ", DefaultValue = true)]
public bool buy { get; set; }
[Parameter("Stop Loss", DefaultValue = 20)]
public int StopLoss { get; set; }
[Parameter("Take Profit", DefaultValue = 150)]
public int TakeProfit { get; set; }
[Parameter("New Position Add", DefaultValue = 20)]
public int NewAdd { get; set; }
private const string mylabel = "POS-INDEX-SAMPLE";
protected override void OnStart()
{
Positions.Closed += OnPositionsClosed1;
// Positions.Closed += OnPositionsClosed2;
Positions.Opened += PositionsOnOpened1;
var position = Positions.Find(mylabel, Symbol);
if (position == null)
{
if (buy == true)
ExecuteMarketOrder(TradeType.Buy, Symbol, InitialVolume, mylabel, StopLoss, TakeProfit);
else
ExecuteMarketOrder(TradeType.Sell, Symbol, InitialVolume, mylabel, StopLoss, TakeProfit);
}
}
////////////////////////////////////////////////////////////////////////////////////
/* I have Some Other uses so Please help me making it Correct by using Position Index,
*/
/////////////////////////////////////////////////////////////////////////////////////////
private void PositionsOnOpened1(PositionOpenedEventArgs args)
{
var position = args.Position;
Position[] poz = Positions.FindAll(mylabel);
var poz1 = poz[0];
var poz2 = poz[1];
foreach (var order in PendingOrders)
{
if (order.Label == position.Label)
{
if (order != null)
CancelPendingOrder(order);
}
}
if (Positions.Count == 1)
{
// one position exit it place One buy and One Sell Pending Order
PlaceStopOrder(TradeType.Buy, Symbol, InitialVolume, position.EntryPrice + NewAdd * Symbol.PipSize, mylabel, NewAdd, TakeProfit);
PlaceStopOrder(TradeType.Sell,Symbol, InitialVolume, position.EntryPrice - NewAdd * Symbol.PipSize, mylabel, NewAdd, TakeProfit);
}
if (poz2 != null)
{
// If poz2 or more position exist
// placing pending order by looking last and 2nd last existing position
if (poz1.TradeType == TradeType.Buy && poz2.TradeType == TradeType.Buy)
{
PlaceStopOrder(TradeType.Buy, Symbol, InitialVolume, position.EntryPrice + NewAdd * Symbol.PipSize, mylabel, NewAdd, TakeProfit);
}
else if (poz1.TradeType == TradeType.Sell && poz2.TradeType == TradeType.Sell)
{
PlaceStopOrder(TradeType.Buy, Symbol, InitialVolume, position.EntryPrice + NewAdd * Symbol.PipSize, mylabel, NewAdd, TakeProfit);
}
}
}
////////////////////////////////////////////////
private void OnPositionsClosed1(PositionClosedEventArgs args)
{
Print("Closed");
var position = args.Position;
Position[] pos = Positions.FindAll(mylabel, Symbol);
var pos1 = pos[0];
var pos2 = pos[1];
if (pos1.GrossProfit < 0)
{
// If last position make loss by Sl it take a new reverse position
if (pos1.TradeType == TradeType.Buy)
ExecuteMarketOrder(TradeType.Buy, Symbol, InitialVolume, mylabel, NewAdd, TakeProfit);
else
ExecuteMarketOrder(TradeType.Sell, Symbol, InitialVolume, mylabel, NewAdd, TakeProfit);
}
if (pos2 != null)
{
// // If last position make loss modity position pos2 Stoploss to Its Entry Price
if (pos1.TradeType != pos2.TradeType)
ModifyPosition(pos2, pos2.EntryPrice, pos2.TakeProfit);
}
}
}
}
@anjupeguforex@gmail.com
anjupeguforex@gmail.com
12 Oct 2017, 06:49
Using an index making IndexOutOfRangeException Error
Using Index makeing IndexOutOfRangeException: Index was outside the bounds of the array.
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class FXGODREWORKING : Robot
{
[Parameter("Position Volume", DefaultValue = 1000, MinValue = 1000, Step = 5000)]
public int InitialVolume { get; set; }
[Parameter("Buy ", DefaultValue = true)]
public bool buy { get; set; }
[Parameter("Stop Loss", DefaultValue = 40)]
public int StopLoss { get; set; }
[Parameter("Take Profit", DefaultValue = 150)]
public int TakeProfit { get; set; }
[Parameter("New Position Add", DefaultValue = 150)]
public int NewAdd { get; set; }
private const string mylabel = "POS-INDEX-SAMPLE";
protected override void OnStart()
{
Positions.Closed += OnPositionsClosed1;
// Positions.Closed += OnPositionsClosed2;
Positions.Opened += PositionsOnOpened1;
var position = Positions.Find(mylabel, Symbol);
if (position == null)
{
if (buy == true)
ExecuteMarketOrder(TradeType.Buy, Symbol, InitialVolume, mylabel, StopLoss, TakeProfit);
else
ExecuteMarketOrder(TradeType.Sell, Symbol, InitialVolume, mylabel, StopLoss, TakeProfit);
}
}
////////////////////////////////////////////////////////////////////////////////////
/* I have Some Other uses so Please help me making it Correct by using Position Index,
*/
/////////////////////////////////////////////////////////////////////////////////////////
private void PositionsOnOpened1(PositionOpenedEventArgs args)
{
var position = args.Position;
Position[] poz = Positions.FindAll(mylabel);
foreach (var order in PendingOrders)
{
if (order.Label == position.Label)
{
if (order != null)
CancelPendingOrder(order);
}
}
if (Positions.Count == 1)
{
// one position exit it place One buy and One Sell Pending Order
PlaceStopOrder(TradeType.Buy, Symbol, InitialVolume, position.EntryPrice + NewAdd * Symbol.PipSize, mylabel, NewAdd, TakeProfit);
PlaceStopOrder(TradeType.Sell, Symbol, InitialVolume, position.EntryPrice - NewAdd * Symbol.PipSize, mylabel, NewAdd, TakeProfit);
}
if (poz[1] != null)
{
// If poz[1] or more position exist
// placing pending order by looking last and 2nd last existing position
if (poz[0].TradeType == TradeType.Buy && poz[1].TradeType == TradeType.Buy)
{
PlaceStopOrder(TradeType.Buy, Symbol, InitialVolume, position.EntryPrice + NewAdd * Symbol.PipSize, mylabel, NewAdd, TakeProfit);
}
else if (poz[0].TradeType == TradeType.Sell && poz[1].TradeType == TradeType.Sell)
{
PlaceStopOrder(TradeType.Buy, Symbol, InitialVolume, position.EntryPrice + NewAdd * Symbol.PipSize, mylabel, NewAdd, TakeProfit);
}
}
}
////////////////////////////////////////////////
private void OnPositionsClosed1(PositionClosedEventArgs args)
{
Print("Closed");
var position = args.Position;
Position[] pos = Positions.FindAll(mylabel, Symbol);
if (pos[0].GrossProfit < 0)
{
// If last position make loss by Sl it take a new reverse position
if (pos[0].TradeType == TradeType.Buy)
ExecuteMarketOrder(TradeType.Buy, Symbol, InitialVolume, mylabel, NewAdd, TakeProfit);
else
ExecuteMarketOrder(TradeType.Sell, Symbol, InitialVolume, mylabel, NewAdd, TakeProfit);
}
if (pos[1] != null)
{
// If last position make loss modity position pos[1] Stoploss to Its Entry Price
if (pos[0].TradeType != pos[1].TradeType)
ModifyPosition(pos[1], pos[1].EntryPrice, pos[1].TakeProfit);
}
}
}
}
@anjupeguforex@gmail.com
anjupeguforex@gmail.com
11 Oct 2017, 09:11
RE: RE: RE:
afhacker said:
anjupeguforex@gmail.com said:
afhacker said:
try this: /algos/indicators/show/1425
Alert.dll is not available .Please help me.
I just updated it and added the DLL files download link with a new test indicator.
Thank you, Thank you, Thank you Many many thanks.
@anjupeguforex@gmail.com
anjupeguforex@gmail.com
11 Oct 2017, 06:39
RE:
afhacker said:
try this: /algos/indicators/show/1425
Alert.dll is not available .Please help me.
@anjupeguforex@gmail.com
anjupeguforex@gmail.com
17 Oct 2017, 06:49
RE: RE: RE:
afhacker said:
Can you add sound option with alert window?
@anjupeguforex@gmail.com