robot progressive
robot progressive
19 Oct 2012, 18:24
hi
to a progressive machine j I need your help
remember, for "robot payback"
[Parameter ("Initial Volume", DefaultValue = 10000, MinValue = 0)]
public int InitialVolume {get; set;}
[Parameter ("Stop Loss", DefaultValue = 20)]
public int StopLoss {get; set;}
[Parameter ("Take Profit", DefaultValue = 20)]
public int TakeProfit {get; set;}
private Position position;
protected override void OnStart ()
{
ExecuteOrder (InitialVolume, TradeType.Sell);
ExecuteOrder (InitialVolume, TradeType.Buy);
.................................................. .......................................
the difficulty was this:
protected override void OnPositionClosed (Position closedPosition)
{
if (closedPosition.GrossProfit> 0)
{
ExecuteOrder (InitialVolume, closedPosition.TradeType);
}
else
{
ExecuteOrder ((int) * 2 closedPosition.Volume, closedPosition.TradeType);
}
}
-------------------------------------------------- -------------------------------
I would like for example:
remember, for "robot payback"
[Parameter ("Initial Volume", DefaultValue = 10000, MinValue = 0)]
public int InitialVolume {get; set;}
[Parameter ("Stop Loss", DefaultValue = 20)]
public int StopLoss {get; set;}
[Parameter ("Take Profit", DefaultValue = 20)]
public int TakeProfit {get; set;}
[Parameter ("Volume", DefaultValue = 1000, MinValue = 0)]
public int Volume {get; set;}
[Parameter ("Stop Loss", DefaultValue = 10)]
public int StopLossInPips {get; set;}
[Parameter ("Take Profit", DefaultValue = 10)]
public int TakeProfitInPips {get; set;}
private Position position;
protected override void OnStart()
{
ExecuteOrder(InitialVolume, TradeType.Sell);
ExecuteOrder(InitialVolume, TradeType.Buy);
ExecuteOrder(Volume, TradeType.Sell);
ExecuteOrder(Volume, TradeType.Buy);
}
..................................................................................
thanks to you I don 'have more problem with take profit and stop loss.
my problem is to combine :
protected override void OnPositionClosed(Position closedPosition)
{
if (closedPosition.GrossProfit > 0)
{
ExecuteOrder(InitialVolume , closedPosition.TradeType);
[ ExecuteOrder(Volume , closedPosition.TradeType); ........??????]
}
else
{
ExecuteOrder((int)closedPosition.Volume * 2, closedPosition.TradeType);
}
}
..........................................................................................................
j have tried many solution and now I'm going crazy...!!!!
merçi beaucoup
Replies
tradermatrix
22 Oct 2012, 12:56
hello
to build a robot progressive, I need to first:
combine two or more martingales (payback).
but with volumes (and takeprofit and stoploss) different.
for example, two martingales:
[Parameter ("InitialVolume",DefaultValue= 10000,MinValue= 0)]
public intInitialVolume{get;set;}
[Parameter("StopLoss",DefaultValue =20)]
public intStopLoss{get;set;}
[Parameter ("Take Profit",DefaultValue =20)]
public intTakeProfit{get;set;}
[Parameter ("Volume",DefaultValue= 1000,MinValue= 0)]
public intVolume{get;set;}
[Parameter("StopLoss",DefaultValue = 10)]
public intStopLossInPips{get;set;}
[Parameter ("Take Profit",DefaultValue = 10)]
public intTakeProfitInPips{get;set;}
privatePositionposition;
protected override void OnStart()
{
ExecuteOrder(InitialVolume, TradeType.Sell);
ExecuteOrder(InitialVolume, TradeType.Buy);
ExecuteOrder(Volume, TradeType.Sell);
ExecuteOrder(Volume, TradeType.Buy);
}
private void ExecuteOrder(int volume, TradeType tradeType)
{
Trade.CreateMarketOrder(tradeType, Symbol, volume);
}
protected override void OnPositionOpened(Position openedPosition)
{
if (openedPosition.Volume == InitialVolume)
{
if (openedPosition.TradeType == TradeType.Buy)
Trade.ModifyPosition(openedPosition, Symbol.Ask - StopLoss*Symbol.PipSize,
Symbol.Ask + TakeProfit*Symbol.PipSize);
else if (openedPosition.TradeType == TradeType.Sell)
Trade.ModifyPosition(openedPosition, Symbol.Bid + StopLoss*Symbol.PipSize,
Symbol.Bid - TakeProfit*Symbol.PipSize);
}
else
{
if (openedPosition.Volume == Volume)
{
if (openedPosition.TradeType == TradeType.Buy)
Trade.ModifyPosition(openedPosition, Symbol.Ask - StopLossInPips* Symbol.PipSize,
Symbol.Ask +TakeProfitInPips * Symbol.PipSize);
else if (openedPosition.TradeType == TradeType.Sell)
Trade.ModifyPosition(openedPosition, Symbol.Bid +StopLossInPips * Symbol.PipSize,
Symbol.Bid - TakeProfitInPips * Symbol.PipSize);
}
position = openedPosition ;
}
______________________________________________________________________________________________________________
my problem arises here.
to combine the two volumes.
so that the two martingales operate separately :
protected override void OnPositionClosed(Position closedPosition)
{
if (closedPosition.GrossProfit > 0)
{
ExecuteOrder(InitialVolume , closedPosition.TradeType);
[ ExecuteOrder(Volume , closedPosition.TradeType); ........??????]
}
else
{
ExecuteOrder((int)closedPosition.Volume * 2, closedPosition.TradeType);
}
}
________________________________________________________________________
thank you for your understanding
excuse me for my english very Approximate
@tradermatrix
admin
22 Oct 2012, 15:48
Hello again,
Do you need to differentiate if the closed position volume is a multiple of InitialVolume or a multiple of Volume?
If so, then:
// closedPosition.Volume is a multiple of InitialVolume
if (closedPosition.Volume % InitialVolume == 0) // the remainder of closedPosition.Volume divided by InitialVolume equals zero
{
if (closedPosition.GrossProfit > 0)
{
ExecuteOrder(InitialVolume, closedPosition.TradeType);
}
else
{
ExecuteOrder((int) closedPosition.Volume*2, closedPosition.TradeType);
}
}
else // closedPosition.Volume is a multiple of Volume
{
if (closedPosition.GrossProfit > 0)
{
ExecuteOrder(Volume, closedPosition.TradeType);
}
else
{
ExecuteOrder((int)closedPosition.Volume * 2, closedPosition.TradeType);
}
}
The above code will work if InitialVolume = 10000 and Volume == 1000
If you modify these two variables, i.e. InitialVolume = 2000 and Volume == 1000 then the logic will fail.
If you want to have the flexibility of adjusting the volume parameter to any value then I suggest using two different robots.
@admin
tradermatrix
23 Oct 2012, 15:30
RE:
Hello again,
Do you need to differentiate if the closed position volume is a multiple of InitialVolume or a multiple of Volume?If so, then:
// closedPosition.Volume is a multiple of InitialVolume
if (closedPosition.Volume % InitialVolume == 0) // the remainder of closedPosition.Volume divided by InitialVolume equals zero
{
if (closedPosition.GrossProfit > 0)
{
ExecuteOrder(InitialVolume, closedPosition.TradeType);
}
else
{
ExecuteOrder((int) closedPosition.Volume*2, closedPosition.TradeType);
}
}
else // closedPosition.Volume is a multiple of Volume
{
if (closedPosition.GrossProfit > 0)
{
ExecuteOrder(Volume, closedPosition.TradeType);
}
else
{
ExecuteOrder((int)closedPosition.Volume * 2, closedPosition.TradeType);
}
}
The above code will work if InitialVolume = 10000 and Volume == 1000
If you modify these two variables, i.e. InitialVolume = 2000 and Volume == 1000 then the logic will fail.
If you want to have the flexibility of adjusting the volume parameter to any value then I suggest using two different robots.
@tradermatrix
tradermatrix
23 Oct 2012, 15:42
hello
the system works for TakeProfit and takeprofitInPips.
when trade is positive (green).
but when stoploss is executed. stoploss is reversed.
it becomes stoplossInPips.
eg
[Parameter ("StopLoss", DefaultValue = 10)]
public intStopLoss {get; set;}
[Parameter ("Take Profit", DefaultValue = 5)]
public intTakeProfitInPips {get; set;}
when stoploss (= 10) is executed it becomes stoplossInPips = 5
the statégie is thus lost.
thank you
__________________________________________________________________________
PAR EXEMPLE
[Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
public int InitialVolume { get; set; }
[Parameter("Stop Loss", DefaultValue = 10)]
public int StopLoss { get; set; }
[Parameter("Take Profit", DefaultValue = 10)]
public int TakeProfit { get; set; }
[Parameter(" Volume", DefaultValue = 1000, MinValue = 0)]
public int Volume { get; set; }
[Parameter("Stop LossInPips", DefaultValue = 5)]
public int StopLossInPips { get; set; }
[Parameter("Take ProfitInPips", DefaultValue = 5)]
public int TakeProfitInPips { get; set; }
private Position position;
protected override void OnStart()
{
ExecuteOrder(InitialVolume,TradeType.Buy );
ExecuteOrder(InitialVolume, TradeType.Sell );
ExecuteOrder(Volume,TradeType.Buy );
ExecuteOrder(Volume, TradeType.Sell );
}
private void ExecuteOrder(int volume, TradeType tradeType)
{
Trade.CreateMarketOrder(tradeType, Symbol, volume);
}
protected override void OnPositionClosed(Position closedPosition)
{
// closedPosition.Volume is a multiple of InitialVolume
if (closedPosition.Volume % InitialVolume == 0) // the remainder of closedPosition.Volume divided by InitialVolume equals zero
{
if (closedPosition.GrossProfit > 0)
{
ExecuteOrder(InitialVolume, closedPosition.TradeType);
}
else
{
ExecuteOrder((int) closedPosition.Volume*2, closedPosition.TradeType);
}
}
else // closedPosition.Volume is a multiple of Volume
{
if (closedPosition.GrossProfit > 0)
{
ExecuteOrder(Volume, closedPosition.TradeType);
}
else
{
ExecuteOrder((int)closedPosition.Volume * 2, closedPosition.TradeType);
}
}
}
protected override void OnPositionOpened(Position openedPosition)
{
if (openedPosition.Volume == InitialVolume)
{
if (openedPosition.TradeType == TradeType.Buy)
Trade.ModifyPosition(openedPosition, Symbol.Ask - StopLoss*Symbol.PipSize,
Symbol.Ask + TakeProfit*Symbol.PipSize);
else if (openedPosition.TradeType == TradeType.Sell)
Trade.ModifyPosition(openedPosition, Symbol.Bid + StopLoss*Symbol.PipSize,
Symbol.Bid - TakeProfit*Symbol.PipSize);
}
else
{
if (openedPosition.TradeType == TradeType.Buy)
Trade.ModifyPosition(openedPosition, Symbol.Ask - StopLossInPips* Symbol.PipSize,
Symbol.Ask +TakeProfitInPips * Symbol.PipSize);
else if (openedPosition.TradeType == TradeType.Sell)
Trade.ModifyPosition(openedPosition, Symbol.Bid +StopLossInPips * Symbol.PipSize,
Symbol.Bid - TakeProfitInPips * Symbol.PipSize);
}
position = openedPosition ;
}
}
}
@tradermatrix
tradermatrix
24 Oct 2012, 17:14
hello
I have always the same problem
when stoploss (= 10) is executed it becomes stoplossInPips = 5
see you soon
@tradermatrix
tradermatrix
25 Oct 2012, 12:52
ho ..! I understood my stupidity ...!
thank you very much for your patience
In fact,
if:
protected override void OnPositionClosed (Position closedPosition)
{
if (closedPosition.Volume% InitialVolume == 0)
...................................
................................
then:
protected override void OnPositionOpened (Position openedPosition)
{
if (closedPosition.Volume% InitialVolume == 0)
.....................................
..................................
c is simple !!
I must be tired ...
I run to the pharmacy to buy vitamins and drugs.
Then, I'll try to build an infernal machine ....
tradermatrix
@tradermatrix
admin
25 Oct 2012, 14:27
Yes, but be careful with the method parameter names:
It should be:
protected override void OnPositionOpened (Position openedPosition)
{
if (openedPosition.Volume%InitialVolume == 0)
{
//...
}
//...
}
@admin
tradermatrix
25 Oct 2012, 15:05
yes .. yes ...!!. c is what I've done on the robot.
c is a mistake on my previous message .. (I had not yet taken the vitamins !!)
thank you again ....
Tradermatrix
@tradermatrix
admin
22 Oct 2012, 11:53
Hello tradematrix,
Glad to hear that the take profit and stop loss implementation was successful previously.
Now, about this issue. Is it possible to explain what you need the robot to do OnPositionClosed? Because from what I see your question is about the logic of your algorithm not about the syntax or any errors you are receiving. So, in order to be able to help you I need to know what you want to accomplish which is not clear from the code above.
By the way, if this is related with a solution in another previously posted thread please continue on that thread or post the solution here.
Best Regards
@admin