//+------------------------------------------------------------------+
//| Aiman - BuySellStop_PO.mq4 |
//| Copyright © 2011, Aiman |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Aiman."
#property link "Aiman"
#property show_inputs
#include <stdlib.mqh>
extern bool PO_buy = false;
extern bool PO_sell = false;
extern double startPrice = 0; //-- Biarkan 0 untuk current price
extern double startLots = 0.01;
extern double multiplier = 2;
extern int totalLayer = 5;
extern int Gap_Between_Pips = 40;
int StopLoss = 0;
int TakeProfit = 0;
int Slippage = 5;
int start()
{
double lot, sl, tp;
int ticket, retry;
double spread = MarketInfo(Symbol(),MODE_SPREAD)*Point;
double ask = Ask+Gap_Between_Pips*Point;
double bid = Bid-Gap_Between_Pips*Point;
if (startPrice != 0)
{
ask = startPrice;
bid = startPrice;
}
for (int i=totalLayer; i>0; i--)
{
if (totalLayer != i)
{
ask = ask+Gap_Between_Pips*Point;
bid = bid-Gap_Between_Pips*Point;
lot = NormalizeDouble(lot*multiplier,2);
}
else lot = startLots;
if (PO_buy)
{
ticket = 0;
retry = 0;
while (ticket<1 && retry<10)
{
if (StopLoss>0) sl=(ask-spread)-(StopLoss*Point); else sl=0;
if (TakeProfit>0) tp=ask+(TakeProfit*Point); else tp=0;
ticket=OrderSend(Symbol(),OP_BUYSTOP,lot,ask,Slippage,sl,tp,"",0,0,Lime);
if (ticket<1) Print ("Order buy limit failed with error ", ErrorDescription(GetLastError()));
Sleep (1000);
retry++;
}
}
if (PO_sell)
{
ticket = 0;
retry = 0;
while (ticket<1 && retry<10)
{
if (StopLoss>0) sl=(bid+spread)+(StopLoss*Point); else sl=0;
if (TakeProfit>0) tp=bid-(TakeProfit*Point); else tp=0;
ticket=OrderSend(Symbol(),OP_SELLSTOP,lot,bid,Slippage,sl,tp,"",0,0,Crimson);
if (ticket<1) Print ("Order sell limit failed with error ", ErrorDescription(GetLastError()));
Sleep (1000);
retry++;
}
}
}
return(0);
}