本文へスキップ

WENGROUP

FX情報FX INF.

limit、stopの
 使用例
limit、stopの使用例です。

//+------------------------------------------------------------------+
//| M15
//| wentomo10
//| qsaved.mq4
//| http://wengroup.net
//+------------------------------------------------------------------+

#define MAGIC 77331017

// parameter
extern double vlimit = 500; //value of limit
extern double vstop = 1200;

extern double Lots = 0.1; //lot
extern int Slippage = 7; //slippage
extern int M5MA_Period = 5;
extern int FastMA_Period = 8; //tanki
extern int SlowMA_Period = 15; //tanki
extern double M5MA1 = 0; //fast heikin before 1
extern double M5MA2 = 0; //fast heikin before 2
extern double FastMA1 = 0; //fast heikin before 1
extern double FastMA2 = 0; //fast heikin before 2
extern double SlowMA1 = 0; //slow heikin before 1
extern double SlowMA2 = 0; //slow heikin before 2
//
extern int psw = 0; //position sw 0:no 1:buy 2:sell
extern int svin = 0; // 1:buy entry ng 2:sell entry ng 0:entry ok
extern int mae = 0; //0:init 1:min 2:max
extern double vpos = 0.00; //value of potiosion
extern double vgen = 0.00; //value of now
extern double vloss = 0.001; //value of stop
extern double buylimit = 0;
extern double sellimit = 0;
extern double buystop = 0;
extern double selstop = 0;
extern double wMA = 0;
extern int sbar = 0; // skiip Bars
extern int previousBar = -1;
//+------------------------------------------------------------------+
//| close |
//+------------------------------------------------------------------+
void ClosePositions()
{

for(int i=0; i<OrdersTotal(); i++)
{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) break;

if(OrderMagicNumber() != MAGIC || OrderSymbol() != Symbol()) continue;

//order type check
if (OrderType() == OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Yellow);
break;

}

if (OrderType() == OP_SELL)
{

OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Green);
break;

}

}

return(0);
}

//+------------------------------------------------------------------+
//| close check |
//+------------------------------------------------------------------+
void Closechk()
{
psw=0;
for(int i=0; i<OrdersTotal(); i++)
{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) break;

if(OrderMagicNumber() != MAGIC || OrderSymbol() != Symbol()) continue;

//order type check
if (OrderType() == OP_BUY)
{
psw=1;

break;

}

if (OrderType() == OP_SELL)
{

psw=2;

break;

}

}

return(0);
}


//+------------------------------------------------------------------+
//| indicator |
//+------------------------------------------------------------------+
void indirtn()
{
//---idouheikin keisan
M5MA1 = iMA(NULL,0,M5MA_Period,0,MODE_SMA,PRICE_CLOSE,1);
M5MA2 = iMA(NULL,0,M5MA_Period,0,MODE_SMA,PRICE_CLOSE,2);
FastMA1 = iMA(NULL,0,FastMA_Period,0,MODE_SMA,PRICE_CLOSE,1);
FastMA2 = iMA(NULL,0,FastMA_Period,0,MODE_SMA,PRICE_CLOSE,2);
SlowMA1 = iMA(NULL,0,SlowMA_Period,0,MODE_SMA,PRICE_CLOSE,1);
SlowMA2 = iMA(NULL,0,SlowMA_Period,0,MODE_SMA,PRICE_CLOSE,2);
wMA = M5MA1 - M5MA2;
//----
return(0);
}
//+------------------------------------------------------------------+
//| entry routin psw 0:nothing 1:buy 2:sell |
//+------------------------------------------------------------------+
void entrtn()
{

//Buy signal ue nuke-----------------------------

if (SlowMA2>FastMA2 && SlowMA1<FastMA1)
{

buylimit = vpos + vlimit*Point;
buystop = vpos - vstop*Point;
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,buystop,buylimit,"",MAGIC,0,Blue);

vpos = Ask;
vgen = vpos;
psw=1;

return(0);

}


//Sell signal sita nuke-------------------------

if (SlowMA2<FastMA2 && SlowMA1>FastMA1)
{

sellimit = vpos - vlimit*Point;
selstop = vpos + vstop*Point;
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,selstop,sellimit,"",MAGIC,0,Red);

vpos = Bid;
vgen = vpos;
psw=2;


}

//----
return(0);
}
//+------------------------------------------------------------------+
//| buy routin psw 0:nothing 1:buy 2:sell |
//+------------------------------------------------------------------+
void buyrtn()
{
if (SlowMA2<FastMA2 && SlowMA1>FastMA1)
{
ClosePositions();
psw=0;

}

//----
return(0);
}

//+------------------------------------------------------------------+
//| sell routin psw 0:nothing 1:buy 2:sell |
//+------------------------------------------------------------------+
void selrtn()
{
if (SlowMA2>FastMA2 && SlowMA1<FastMA1)
{
ClosePositions();
psw=0;

}


//----
return(0);
}

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int init()
{
Print("******* start testav1 ****** good luck!!");
psw = 0;
vpos = 0;
vgen = Bid;

//----
return(0);
}

//+------------------------------------------------------------------+
//| expert deinit function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
indirtn();
Closechk();
if (psw==1) buyrtn();
if (psw==2) selrtn();
if (psw==0) entrtn();


//----
return(0);
}