TRAILING STOP is a wonderful startegy that allow your fund will not loss a lot in one tarde , and can let you gain big profit when strong trend exist .
below is a trailing stop program, it get 0 error, but have 3 warnings after compile, do anyone tell me do anywhere that i should amend?
the 3 warning is :
1)
'UseTrailing' - expression on global scope not allowed C:\Program Files\FxPro MetaTrader\experts\scripts\b-TLE_v.1.6.mqh (52, 6)
2)
'TrailingPositions' - expression on global scope not allowed C:\Program Files\FxPro MetaTrader\experts\scripts\b-TLE_v.1.6.mqh (52, 19)
3)
Start function not found and cannot be run.
BELOW IS THE WHOLE PROGRAM:
//+------------------------------------------------------------------+
//| b-TLE_v.1.6.mqh |
//| 抌?闉?? aka KimIV |
//| Àâòîìàòèçàöèÿ òîðãîâëè íà ôèíàíñîâûõ ðûíêàõ - Ãëàâíàÿ |
//| |
//| 20.09.2005 秮跳鶇鍒翴瘔 鼨嚦樦?禖羻儋?(Three Level Exit). |
//| 昳譇摳譖瘔殣 碫?闅膴 瀁賥灕? |
//| 醫鸆譔 襜錪膰 縺 鍱鴈 錌搿?蜸僳鴀. |
//| 22.09.2005 v.1.0 邇賈 碴氂膻?櫡譇懤襝 儇 鵿譇碲樇? 賧膼? |
//| 碲?膻 勷瞂襡鴀? |
//| 22.09.2005 v.1.1 邇賈 櫡譇懤襝?儇 鍏譇膻灚膻?瀁 壝跟? |
//| 22.09.2005 v.1.2 瀔飶鳹 霟魨膧 ?闀謥麧錼膻樦 瘔錌譖. |
//| 22.09.2005 v.1.3 凎鳪鳿鍒鳪 懤矐膻賚 闅鼫癰?劖鳽樇? 欈蕻. |
//| 22.09.2005 v.1.4 砐瀔飶鳹 懤矐膻賚 闅鼫癰?劖鳽樇? 欈蕻. |
//| 23.09.2005 v.1.5 凎鳪鳿鍒鳪 邍膷儚殥膧?鵨蠉膼瞃?嚦闀鍒. |
//| 14.10.2005 v.1.6 秮?鶇鍒? 櫇謥膼黟 嚦闀? |
//| 23.11.2005 v.1.6 凎鳪鳿僪? ?睯麧 鵯魤歑黟錪膼蜦 斁劌?. |
//| 犧 黓瀁錪賧瘔膻 儋摳睯譔 嚦豂膧 ?斁劌錼 start |
//| if (UseTrailing) TrailingPositions(); |
//+------------------------------------------------------------------+
#property copyright "抌?闉?? aka KimIV"
#property link "http://www.kimiv.ru"
#include <sampledll.mqh>
#include <stdlib.mqh>
//------- 鎮氂膻?櫡譇懤襝?斁劌? -----------------------------------
extern string _Parameters_Trailing = "----- 眈譇懤襝?襝鳪?;
extern bool UseTrailing = True; // 瀁錪賧瘔譔 襝鳪;
extern int LevelProfit1 = 20; // 盷謼 鶇鍒樇?瀔隮鼏?
extern int LevelMoving1 = 1; // 盷謼 鶇鍒樇?櫇謥膼黟
extern int LevelProfit2 = 35; // 鎗闉鍣 鶇鍒樇?瀔隮鼏?
extern int LevelMoving2 = 20; // 鎗闉鍣 鶇鍒樇?櫇謥膼黟
extern int LevelProfit3 = 55; // 秮殣鴇 鶇鍒樇?瀔隮鼏?
extern int LevelMoving3 = 30; // 秮殣鴇 鶇鍒樇?櫇謥膼黟
extern int TrailingStop = 40; // 冓賚歑 襝鳪?
extern int TrailingStep = 5; // 嵑?襝鳪?
extern bool UseSound = True; // Use sound
extern string NameFileSound = "expert.wav"; // name of the file for the sound
extern color clModifyBuy = Yellow; // Color of the modifybuy
extern color clModifySell = Pink; //
#define MAGIC 20051119
int Global_flag;
int start();
if (UseTrailing) TrailingPositions();
//+------------------------------------------------------------------+
//| 栦瀔鍒鍻麧膻?瀁賥灕? |
//+------------------------------------------------------------------+
void TrailingPositions() {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
ThreeLevelSystemOfOutput();
}
}
}
}
//+------------------------------------------------------------------+
//| 秮跳鶇鍒翴瘔 鼨嚦樦?禖羻儋? |
//+------------------------------------------------------------------+
void ThreeLevelSystemOfOutput() {
int
pr=ProfitPosition(), sl=StopLossInPoint();
int sp=MarketInfo(OrderSymbol(), MODE_SPREAD);
if (
pr>LevelProfit1 &&
pr<=LevelProfit2 && sl<LevelMoving1) ModifyStopLossInPoint(LevelMoving1);
if (
pr>LevelProfit2 &&
pr<=LevelProfit3 && sl<LevelMoving2) ModifyStopLossInPoint(LevelMoving2);
if (
pr>LevelProfit3 && sl<LevelMoving3) ModifyStopLossInPoint(LevelMoving3);
if (
pr>LevelMoving3+TrailingStop+TrailingStep) {
SimpleTrailingPositions();
}
}
//+------------------------------------------------------------------+
//| 栦瀔鍒鍻麧膻?瀁賥灕?瀔闃譖?襝鳪鍎 |
//+------------------------------------------------------------------+
void SimpleTrailingPositions() {
double pBid, pAsk, pp=MarketInfo(OrderSymbol(), MODE_POINT);
if (OrderType()==OP_BUY) {
pBid=MarketInfo(OrderSymbol(), MODE_BID);
if (pBid-OrderOpenPrice()>TrailingStop*pp) {
if (OrderStopLoss()<pBid-(TrailingStop+TrailingStep-1)*pp) {
ModifyStopLoss(pBid-TrailingStop*pp, clModifyBuy);
return;
}
}
}
if (OrderType()==OP_SELL) {
pAsk=MarketInfo(OrderSymbol(), MODE_ASK);
if (OrderOpenPrice()-pAsk>TrailingStop*pp) {
if (OrderStopLoss()>pAsk+(TrailingStop+TrailingStep-1)*pp || OrderStopLoss()==0) {
ModifyStopLoss(pAsk+TrailingStop*pp, clModifySell);
return;
}
}
}
}
//+------------------------------------------------------------------+
//| 盷謥膼?鶇鍒? StopLoss |
//| 眈譇懤襝? |
//| ldStopLoss - 鶇鍒樇?StopLoss |
//+------------------------------------------------------------------+
void ModifyStopLoss(double ldStopLoss, color clModify) {
bool fm; // 婑飹 斁儰鐓罻灕?瀁賥灕?
int err;
if (IsTradeAllowed()) {
fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSt opLoss,OrderTakeProfit(),0,clModify);
if (!fm) {
err=GetLastError();
Print("Error(",err,") modifying: ",ErrorDescription(err));
}
if (fm && UseSound) PlaySound(NameFileSound);
}
}
//+------------------------------------------------------------------+
//| 盷謥膼?鶇鍒? StopLoss |
//| 眈譇懤襝? |
//| ldStopLoss - 鶇鍒樇?StopLoss |
//+------------------------------------------------------------------+
void ModifyStopLossInPoint(int pp) {
bool fm;
color clModify;
double ldSL=0, mp=MarketInfo(OrderSymbol(), MODE_POINT);
int err;
if (OrderType()==OP_BUY) {
ldSL=OrderOpenPrice()+pp*mp;
clModify=clModifyBuy;
}
if (OrderType()==OP_SELL) {
ldSL=OrderOpenPrice()-pp*mp;
clModify=clModifySell;
}
if (IsTradeAllowed()) {
fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL ,OrderTakeProfit(),0,clModify);
if (!fm) {
err=GetLastError();
Print("Error(",err,") modifying: ",ErrorDescription(err));
}
if (fm && UseSound) PlaySound(NameFileSound);
}
}
//+------------------------------------------------------------------+
//| 鎬誺譇╠殣 瀔隮鼏 瀁賥灕??瀀臌蠉? |
//+------------------------------------------------------------------+
int ProfitPosition()
{
double pBid, pAsk, pp=MarketInfo(OrderSymbol(), MODE_POINT);
double
pr=0;
if (OrderType()==OP_BUY)
{
pBid=MarketInfo(OrderSymbol(), MODE_BID);
pr=(pBid-OrderOpenPrice())/pp;
}
if (OrderType()==OP_SELL)
{
pAsk=MarketInfo(OrderSymbol(), MODE_ASK);
pr=(OrderOpenPrice()-pAsk)/pp;
}
return(MathRound(
pr));
}
//+------------------------------------------------------------------+
//| 鎬誺譇╠殣 StopLoss 瀁賥灕??瀀臌蠉? |
//+------------------------------------------------------------------+
int StopLossInPoint() {
double pp=MarketInfo(OrderSymbol(), MODE_POINT);
double sp=0;
if (OrderType()==OP_BUY) {
sp=(OrderStopLoss()-OrderOpenPrice())/pp;
}
if (OrderType()==OP_SELL) {
sp=(OrderOpenPrice()-OrderStopLoss())/pp;
}
if (OrderStopLoss()==0) sp=-OrderOpenPrice()/pp;
return(MathRound(sp));
return(0);
}
//+------------------------------------------------------------------+
can ANYONE HELP ME TO DEBUG AND POST IT HERE
big THANKYOU