设为首页 收藏本站 切换语言

海龟交易系统 MT4 源码  

| 发表于 2021-6-16 18:03:11 | 显示全部楼层 |复制链接

海龟交易系统 MT4 源码


//±-----------------------------------------------------------------+
//| GoHan Turtle Trader.mq4 |
//| Copyright ?2008, gohanforex.com |
//| http://www.gohanforex.com |
//±-----------------------------------------------------------------+
#property copyright “Copyright ?2008, gohanforex.com”
#property link “http://www.zhongjie110.com”

extern color LabelColor=White;
extern int LabelFontSize=8;
extern color S1LongEntryLineColor=Blue;
extern color S2LongEntryLineColor=LightBlue;
extern color S1andS2LongEntryLineColor=Lime;
extern color S1ExitLinesColor=Yellow;
extern color S1ShortEntryLineColor=Red;
extern color S2ShortEntryLineColor=Pink;
extern color S1andS2ShortEntryLineColor=Orange;

int MaxCommentsToShow=25;
string allcomments[];
datetime lastcheck;
bool periodOK=false;
int MagicNumber=12345;

int S1Periods=20;
int S2Periods=55;
double S1LongEntry=0;
double S1ShortEntry=0;
double S2LongEntry=0;
double S2ShortEntry=0;

double S1LongExit=0;
double S1ShortExit=0;
double S2LongExit=0;
double S2ShortExit=0;

int S1LongEntryBar=0;
int S1ShortEntryBar=0;
int S2LongEntryBar=0;
int S2ShortEntryBar=0;

int S1LongExitBar=0;
int S1ShortExitBar=0;

double HighPriceArray[];
double LowPriceArray[];

double CurrentATR;
double UnitSizing;
double TradeRisk=0.01;
int ATRTakeProfitMultiplier=2;
int ATRStopLossMultiplier=2;

//±-----------------------------------------------------------------+
//| expert initialization function |
//±-----------------------------------------------------------------+
int init()
{
manageupperstatus(“GoHan Turtles Trader - gohanforex.com, CR 2009”);
if(Period()==1440)
{
periodOK=true;
managelowerstatus(“http://www.gohanforex.com”);
managecomments(“Turtle Trading Started”);
CalcTurtleValues();
drawentries(S1LongEntry, S2LongEntry, S1ShortEntry, S2ShortEntry, S1LongExit, S1ShortExit);
}
else
{
periodOK=false;
managelowerstatus(“ERROR: This scanner must be used on an D1 chart”);
managecomments(“MUST USE D1 TIMEFRAME - WILL NOT SCAN”);
deinit();
}

return(0);
}
//±-----------------------------------------------------------------+
//| expert deinitialization function |
//±-----------------------------------------------------------------+
int deinit()
{
return(0);
}
//±-----------------------------------------------------------------+
//| expert start function |
//±-----------------------------------------------------------------+
int start()
{
if(periodOK==false) return(0);
//Check for a new bar
if(lastcheck<Time[0])
{
//A new bar has formed and new values need to be computed
string checktime=TimeToStr(TimeLocal(),TIME_DATE);
lastcheck=Time[0];
CalcTurtleValues();
drawentries(S1LongEntry, S2LongEntry, S1ShortEntry, S2ShortEntry, S1LongExit, S1ShortExit);
managecomments(checktime +": New values calculated");
}

//managecomments(MarketInfo(Symbol(),MODE_TICKVALUE));

//Always do the trade management functions
//Check for orders to close
//Close positions based on the 10-day number
if(Bid<S1LongExit)
{
//Close long positions
CloseS1LongPositions();
ClosePendingLongPositions();
}

if(Ask>S1ShortExit)
{
//Close short positions
CloseS1ShortPositions();
ClosePendingShortPositions();
}

//Check for S2 long entry
if((S2LongEntry<Ask)&&(CountLongPositions()==0))
{
//Need new long positions
CurrentATR=iATR(Symbol(),PERIOD_D1,S1Periods,1);
UnitSizing=(AccountBalance()*TradeRisk)/(CurrentATR/Point)/MarketInfo(Symbol(),MODE_TICKVALUE);
UnitSizing=NormalizeDouble(UnitSizing,2);
//Close the short positions
CloseS1ShortPositions();
CloseS2ShortPositions();
ClosePendingShortPositions();
ClosePendingLongPositions();
//Need a new long position
OpenS2LongPositions();
}

//Check for S1 long entry
if((S1LongEntry<Ask)&&(CountLongPositions()==0))
{
//Need new long positions
CurrentATR=iATR(Symbol(),PERIOD_D1,S1Periods,1);
UnitSizing=(AccountBalance()*TradeRisk)/(CurrentATR/Point)/MarketInfo(Symbol(),MODE_TICKVALUE);
UnitSizing=NormalizeDouble(UnitSizing,2);
//Close the short positions
CloseS1ShortPositions();
CloseS2ShortPositions();
ClosePendingShortPositions();
ClosePendingLongPositions();
//Need a new long position
OpenS1LongPositions();
}

//Check for S2 short entry
if((S2ShortEntry>Bid)&&(CountShortPositions()==0))
{
//Need new short positions
CurrentATR=iATR(Symbol(),PERIOD_D1,S1Periods,1);
UnitSizing=(AccountBalance()*TradeRisk)/(CurrentATR/Point)/MarketInfo(Symbol(),MODE_TICKVALUE);
UnitSizing=NormalizeDouble(UnitSizing,2);
//Close the long positions
CloseS1LongPositions();
CloseS2LongPositions();
ClosePendingLongPositions();
ClosePendingShortPositions();
//Need a new short position
OpenS2ShortPositions();
}

//Check for S1 short entry
if((S1ShortEntry>Bid)&&(CountShortPositions()==0))
{
//Need new short positions
CurrentATR=iATR(Symbol(),PERIOD_D1,S1Periods,1);
UnitSizing=(AccountBalance()*TradeRisk)/(CurrentATR/Point)/MarketInfo(Symbol(),MODE_TICKVALUE);
UnitSizing=NormalizeDouble(UnitSizing,2);
//Close the long positions
CloseS1LongPositions();
CloseS2LongPositions();
ClosePendingLongPositions();
ClosePendingShortPositions();
//Need a new short position
OpenS1ShortPositions();
}

if(OrdersTotal()>0)
{
//Standardize the stops
StandardStopsForShorts();
StandardStopsForLongs();
}
return(0);
}
//±-----------------------------------------------------------------+

void CalcTurtleValues()
{
//Prepare and fill the two arrays
int pricecounter=0;
ArrayResize(HighPriceArray,S2Periods);
ArrayResize(LowPriceArray,S2Periods);
for(pricecounter=0;pricecounter<S2Periods;pricecounter++)
{
HighPriceArray[pricecounter]=High[pricecounter+1];
LowPriceArray[pricecounter]=Low[pricecounter+1];
}

S1LongEntryBar=ArrayMaximum(HighPriceArray,S1Periods,0);
S1ShortEntryBar=ArrayMinimum(LowPriceArray,S1Periods,0);
S2LongEntryBar=ArrayMaximum(HighPriceArray,WHOLE_ARRAY,0);
S2ShortEntryBar=ArrayMinimum(LowPriceArray,WHOLE_ARRAY,0);

S1LongExitBar=ArrayMinimum(LowPriceArray,10,0);
S1ShortExitBar=ArrayMaximum(HighPriceArray,10,0);

S1LongEntry=HighPriceArray[S1LongEntryBar];
S1ShortEntry=LowPriceArray[S1ShortEntryBar];
S2LongEntry=HighPriceArray[S2LongEntryBar];
S2ShortEntry=LowPriceArray[S2ShortEntryBar];

S1LongExit=LowPriceArray[S1LongExitBar];
S1ShortExit=HighPriceArray[S1ShortExitBar];
S2LongExit=S1ShortEntry;
S2ShortExit=S1LongEntry;
}

//±-----------------------------------------------------------------+
//| Manage comments |
//±-----------------------------------------------------------------+
void managecomments(string addcomment)
{
string basemessage = “Current Turtle Order Entry Informationn”;
string tempcomments[];
int commentscroll;
string output = basemessage;
int CommentCount = ArrayRange(allcomments, 0);
if(CommentCount<MaxCommentsToShow)
{
ArrayResize(tempcomments,CommentCount+1);
ArrayCopy(tempcomments,allcomments,1,0,WHOLE_ARRAY);
}
else
{
ArrayResize(tempcomments,MaxCommentsToShow);
ArrayCopy(tempcomments,allcomments,1,0,MaxCommentsToShow-1);
}
tempcomments[0]=addcomment;
CommentCount = ArrayRange(tempcomments, 0);
ArrayResize(allcomments,CommentCount);
ArrayCopy(allcomments,tempcomments,0,0,CommentCount);

for(commentscroll=0;commentscroll<CommentCount;commentscroll++)
{
output = output + allcomments[commentscroll] +“n”;
}
Comment(output);
}

void drawentries(double S1Long, double S2Long, double S1Short, double S2Short, double S1LongExit, double S1ShortExit)
{
ObjectDelete(“S1Long_Entry”);
ObjectDelete(“S1Long_EntrySign”);
ObjectDelete(“S2Long_Entry”);
ObjectDelete(“S2Long_EntrySign”);

ObjectDelete(“S2Short_EntrySign”);
ObjectDelete(“S2Short_Entry”);
ObjectDelete(“S1Short_EntrySign”);
ObjectDelete(“S1Short_Entry”);

ObjectDelete(“S1Long_ExitSign”);
ObjectDelete(“S1Long_Exit”);

ObjectDelete(“S1Short_ExitSign”);
ObjectDelete(“S1Short_Exit”);

if(S1LongExit!=S1Short)
{
ObjectCreate(“S1Long_Exit”, OBJ_HLINE, 0, 0, S1LongExit);// Creating obj.
ObjectSet(“S1Long_Exit”,OBJPROP_COLOR,S1ExitLinesColor);
ObjectCreate(“S1Long_ExitSign”, OBJ_TEXT, 0, Time[0], S1LongExit);// Creating obj.
ObjectSetText(“S1Long_ExitSign”, "S1 Long Exit: "+DoubleToStr(S1LongExit,Digits), LabelFontSize, “Verdana”, LabelColor);
}

if(S1ShortExit!=S1Long)
{
ObjectCreate(“S1Short_Exit”, OBJ_HLINE, 0, 0, S1ShortExit);// Creating obj.
ObjectSet(“S1Short_Exit”,OBJPROP_COLOR,S1ExitLinesColor);
ObjectCreate(“S1Short_ExitSign”, OBJ_TEXT, 0, Time[0], S1ShortExit);// Creating obj.
ObjectSetText(“S1Short_ExitSign”, "S1 Short Exit: "+DoubleToStr(S1ShortExit,Digits), LabelFontSize, “Verdana”, LabelColor);
}

if(S1Long==S2Long)
{
ObjectCreate(“S1Long_Entry”, OBJ_HLINE, 0, 0, S1Long);// Creating obj.
ObjectSet(“S1Long_Entry”,OBJPROP_COLOR,S1andS2LongEntryLineColor);
ObjectCreate(“S1Long_EntrySign”, OBJ_TEXT, 0, Time[0], S1Long);// Creating obj.
ObjectSetText(“S1Long_EntrySign”, "S1 & S2: "+DoubleToStr(S1Long,Digits), LabelFontSize, “Verdana”, LabelColor);
}
else
{
ObjectCreate(“S1Long_Entry”, OBJ_HLINE, 0, 0, S1Long);// Creating obj.
ObjectSet(“S1Long_Entry”,OBJPROP_COLOR,S1LongEntryLineColor);

  ObjectCreate("S1Long_EntrySign", OBJ_TEXT, 0, Time[0], S1Long);// Creating obj.  ObjectSetText("S1Long_EntrySign", "S1: "+DoubleToStr(S1Long,Digits), LabelFontSize, "Verdana", LabelColor);      ObjectCreate("S2Long_Entry", OBJ_HLINE, 0, 0, S2Long);// Creating obj.  ObjectSet("S2Long_Entry",OBJPROP_COLOR,S2LongEntryLineColor);      ObjectCreate("S2Long_EntrySign", OBJ_TEXT, 0, Time[0], S2Long);// Creating obj.  ObjectSetText("S2Long_EntrySign", "S2: "+DoubleToStr(S2Long,Digits), LabelFontSize, "Verdana", LabelColor);  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

//======

if(S1Short==S2Short)
{
ObjectCreate(“S1Short_Entry”, OBJ_HLINE, 0, 0, S1Short);// Creating obj.
ObjectSet(“S1Short_Entry”,OBJPROP_COLOR,S1andS2ShortEntryLineColor);

  ObjectCreate("S1Short_EntrySign", OBJ_TEXT, 0, Time[0], S1Short);// Creating obj.  ObjectSetText("S1Short_EntrySign", "S1 & S2: "+DoubleToStr(S1Short,Digits), LabelFontSize, "Verdana", LabelColor);  }
  • 1
  • 2
  • 3

else
{
ObjectCreate(“S1Short_Entry”, OBJ_HLINE, 0, 0, S1Short);// Creating obj.
ObjectSet(“S1Short_Entry”,OBJPROP_COLOR,S1ShortEntryLineColor);

  ObjectCreate("S1Short_EntrySign", OBJ_TEXT, 0, Time[0], S1Short);// Creating obj.  ObjectSetText("S1Short_EntrySign", "S1: "+DoubleToStr(S1Short,Digits), LabelFontSize, "Verdana", LabelColor);  ObjectCreate("S2Short_Entry", OBJ_HLINE, 0, 0, S2Short);// Creating obj.  ObjectSet("S2Short_Entry",OBJPROP_COLOR,S2ShortEntryLineColor);  ObjectCreate("S2Short_EntrySign", OBJ_TEXT, 0, Time[0], S2Short);// Creating obj.  ObjectSetText("S2Short_EntrySign", "S2: "+DoubleToStr(S2Short,Digits), LabelFontSize, "Verdana", LabelColor);  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

}

//±-----------------------------------------------------------------+
//| Manage upper status |
//±-----------------------------------------------------------------+
void manageupperstatus(string addstatus)
{
ObjectDelete(“Upper_Status”);
if(addstatus!="")
{
ObjectCreate(“Upper_Status”, OBJ_LABEL, 0, 0, 0);// Creating obj.
ObjectSet(“Upper_Status”, OBJPROP_CORNER,1); // Reference corner
ObjectSet(“Upper_Status”, OBJPROP_XDISTANCE, 2);// X coordinate
ObjectSet(“Upper_Status”, OBJPROP_YDISTANCE, 13);// Y coordinate
ObjectSetText(“Upper_Status”, addstatus, 9, “Verdana”, White);
}
}

//±-----------------------------------------------------------------+
//| Manage lower status |
//±-----------------------------------------------------------------+
void managelowerstatus(string addstatus)
{
ObjectDelete(“Lower_Status”);
if(addstatus!="")
{
ObjectCreate(“Lower_Status”, OBJ_LABEL, 0, 0, 0);// Creating obj.
ObjectSet(“Lower_Status”, OBJPROP_CORNER,3); // Reference corner
ObjectSet(“Lower_Status”, OBJPROP_XDISTANCE, 2);// X coordinate
ObjectSet(“Lower_Status”, OBJPROP_YDISTANCE, 1);// Y coordinate
ObjectSetText(“Lower_Status”, addstatus, 9, “Verdana”, Yellow);
}
}

void OpenS1LongPositions()
{
double order1price;
double order2price;
double order3price;

OrderSend(Symbol(),OP_BUY,UnitSizing,Ask,0,LongStopLoss(Ask,CurrentATR),LongTakeProfit(Ask,CurrentATR),“S1”,MagicNumber,0,Blue);
order1price=Ask+(CurrentATR/2);
order2price=Ask+CurrentATR;
order3price=order2price+(CurrentATR/2);

order1price=NormalizeDouble(order1price,Digits);
order2price=NormalizeDouble(order2price,Digits);
order3price=NormalizeDouble(order3price,Digits);

OrderSend(Symbol(),OP_BUYSTOP,UnitSizing,order1price,0,LongStopLoss(order1price,CurrentATR),LongTakeProfit(order1price,CurrentATR),“S1”,MagicNumber,0,Blue);
OrderSend(Symbol(),OP_BUYSTOP,UnitSizing,order2price,0,LongStopLoss(order2price,CurrentATR),LongTakeProfit(order2price,CurrentATR),“S1”,MagicNumber,0,Blue);
OrderSend(Symbol(),OP_BUYSTOP,UnitSizing,order3price,0,LongStopLoss(order3price,CurrentATR),LongTakeProfit(order3price,CurrentATR),“S1”,MagicNumber,0,Blue);
}

void OpenS2LongPositions()
{
double order1price;
double order2price;
double order3price;

OrderSend(Symbol(),OP_BUY,UnitSizing,Ask,0,LongStopLoss(Ask,CurrentATR),LongTakeProfit(Ask,CurrentATR),“S2”,MagicNumber,0,Blue);
order1price=Ask+(CurrentATR/2);
order2price=Ask+CurrentATR;
order3price=order2price+(CurrentATR/2);

order1price=NormalizeDouble(order1price,Digits);
order2price=NormalizeDouble(order2price,Digits);
order3price=NormalizeDouble(order3price,Digits);

OrderSend(Symbol(),OP_BUYSTOP,UnitSizing,order1price,0,LongStopLoss(order1price,CurrentATR),LongTakeProfit(order1price,CurrentATR),“S2”,MagicNumber,0,Blue);
OrderSend(Symbol(),OP_BUYSTOP,UnitSizing,order2price,0,LongStopLoss(order2price,CurrentATR),LongTakeProfit(order2price,CurrentATR),“S2”,MagicNumber,0,Blue);
OrderSend(Symbol(),OP_BUYSTOP,UnitSizing,order3price,0,LongStopLoss(order3price,CurrentATR),LongTakeProfit(order3price,CurrentATR),“S2”,MagicNumber,0,Blue);
}

void OpenS1ShortPositions()
{
double order1price;
double order2price;
double order3price;

OrderSend(Symbol(),OP_SELL,UnitSizing,Bid,0,ShortStopLoss(Bid,CurrentATR),ShortTakeProfit(Bid,CurrentATR),“S1”,MagicNumber,0,Red);
order1price=Bid-(CurrentATR/2);
order2price=Bid-CurrentATR;
order3price=order2price-(CurrentATR/2);

order1price=NormalizeDouble(order1price,Digits);
order2price=NormalizeDouble(order2price,Digits);
order3price=NormalizeDouble(order3price,Digits);

OrderSend(Symbol(),OP_SELLSTOP,UnitSizing,order1price,0,ShortStopLoss(order1price,CurrentATR),ShortTakeProfit(order1price,CurrentATR),“S1”,MagicNumber,0,Red);
OrderSend(Symbol(),OP_SELLSTOP,UnitSizing,order2price,0,ShortStopLoss(order2price,CurrentATR),ShortTakeProfit(order2price,CurrentATR),“S1”,MagicNumber,0,Red);
OrderSend(Symbol(),OP_SELLSTOP,UnitSizing,order3price,0,ShortStopLoss(order3price,CurrentATR),ShortTakeProfit(order3price,CurrentATR),“S1”,MagicNumber,0,Red);
}

void OpenS2ShortPositions()
{
double order1price;
double order2price;
double order3price;

OrderSend(Symbol(),OP_SELL,UnitSizing,Bid,0,ShortStopLoss(Bid,CurrentATR),ShortTakeProfit(Bid,CurrentATR),“S2”,MagicNumber,0,Red);
order1price=Bid-(CurrentATR/2);
order2price=Bid-CurrentATR;
order3price=order2price-(CurrentATR/2);

order1price=NormalizeDouble(order1price,Digits);
order2price=NormalizeDouble(order2price,Digits);
order3price=NormalizeDouble(order3price,Digits);

OrderSend(Symbol(),OP_SELLSTOP,UnitSizing,order1price,0,ShortStopLoss(order1price,CurrentATR),ShortTakeProfit(order1price,CurrentATR),“S2”,MagicNumber,0,Red);
OrderSend(Symbol(),OP_SELLSTOP,UnitSizing,order2price,0,ShortStopLoss(order2price,CurrentATR),ShortTakeProfit(order2price,CurrentATR),“S2”,MagicNumber,0,Red);
OrderSend(Symbol(),OP_SELLSTOP,UnitSizing,order3price,0,ShortStopLoss(order3price,CurrentATR),ShortTakeProfit(order3price,CurrentATR),“S2”,MagicNumber,0,Red);
}

double LongStopLoss(double StartPrice, double CurrentATR)
{
double result;
result=StartPrice-(CurrentATR*ATRStopLossMultiplier);
result=NormalizeDouble(result,Digits);
return(result);
}

double LongTakeProfit(double StartPrice, double CurrentATR)
{
double result;
result=StartPrice+(CurrentATR*ATRTakeProfitMultiplier);
result=NormalizeDouble(result,Digits);
return(result);
}

double ShortStopLoss(double StartPrice, double CurrentATR)
{
double result;
result=StartPrice+(CurrentATR*ATRStopLossMultiplier);
result=NormalizeDouble(result,Digits);
return(result);
}

double ShortTakeProfit(double StartPrice, double CurrentATR)
{
double result;
result=StartPrice-(CurrentATR*ATRTakeProfitMultiplier);
result=NormalizeDouble(result,Digits);
return(result);
}

void CloseS1LongPositions()
{
int totalorders=OrdersTotal();
int orderscroll;
for(orderscroll=0;orderscroll<totalorders;orderscroll++)
{
OrderSelect(orderscroll,SELECT_BY_POS,MODE_TRADES);
if((OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber)&&((OrderType()OP_BUY))&&((OrderComment()“S1”)))
{
OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
}
}
}

void CloseS2LongPositions()
{
int totalorders=OrdersTotal();
int orderscroll;
for(orderscroll=0;orderscroll<totalorders;orderscroll++)
{
OrderSelect(orderscroll,SELECT_BY_POS,MODE_TRADES);
if((OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber)&&((OrderType()OP_BUY))&&((OrderComment()“S2”)))
{
OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
}
}
}

void ClosePendingLongPositions()
{
int totalorders=OrdersTotal();
int orderscroll;
for(orderscroll=0;orderscroll<totalorders;orderscroll++)
{
OrderSelect(orderscroll,SELECT_BY_POS,MODE_TRADES);
if((OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber)&&((OrderType()==OP_BUYSTOP)))
{
OrderDelete(OrderTicket());
}
}
}

int CountLongPositions()
{
int totalorders=OrdersTotal();
int orderscroll;
int result=0;
for(orderscroll=0;orderscroll<totalorders;orderscroll++)
{
OrderSelect(orderscroll,SELECT_BY_POS,MODE_TRADES);
if((OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber)&&((OrderType()==OP_BUY)))
{
result++;
}
}
return(result);
}

void CloseS1ShortPositions()
{
int totalorders=OrdersTotal();
int orderscroll;
for(orderscroll=0;orderscroll<totalorders;orderscroll++)
{
OrderSelect(orderscroll,SELECT_BY_POS,MODE_TRADES);
if((OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber)&&((OrderType()OP_SELL))&&((OrderComment()“S1”)))
{
OrderClose(OrderTicket(),OrderLots(),Ask,0,Blue);
}
}
}

void CloseS2ShortPositions()
{
int totalorders=OrdersTotal();
int orderscroll;
for(orderscroll=0;orderscroll<totalorders;orderscroll++)
{
OrderSelect(orderscroll,SELECT_BY_POS,MODE_TRADES);
if((OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber)&&((OrderType()OP_SELL))&&((OrderComment()“S2”)))
{
OrderClose(OrderTicket(),OrderLots(),Ask,0,Blue);
}
}
}

void ClosePendingShortPositions()
{
int totalorders=OrdersTotal();
int orderscroll;
for(orderscroll=0;orderscroll<totalorders;orderscroll++)
{
OrderSelect(orderscroll,SELECT_BY_POS,MODE_TRADES);
if((OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber)&&((OrderType()==OP_SELLSTOP)))
{
OrderDelete(OrderTicket());
}
}
}

int CountShortPositions()
{
int totalorders=OrdersTotal();
int orderscroll;
int result=0;
for(orderscroll=0;orderscroll<totalorders;orderscroll++)
{
OrderSelect(orderscroll,SELECT_BY_POS,MODE_TRADES);
if((OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber)&&((OrderType()==OP_SELL)))
{
result++;
}
}
return(result);
}

void StandardStopsForShorts()
{
double stoplevel=10000;
int orderscroll;
int totalshorts=CountShortPositions();
int totalorders=OrdersTotal();
if(totalshorts>1)
{
//scroll to find the lowest stop
for(orderscroll=0;orderscroll<totalorders;orderscroll++)
{
OrderSelect(orderscroll,SELECT_BY_POS,MODE_TRADES);
if((OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber)&&((OrderType()==OP_SELL)))
{
if(OrderStopLoss()<stoplevel)
{
stoplevel=OrderStopLoss();
}
}
}

  //scroll to set the stops  for(orderscroll=0;orderscroll<totalorders;orderscroll++)     {     OrderSelect(orderscroll,SELECT_BY_POS,MODE_TRADES);     if((OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber)&&((OrderType()==OP_SELL)))        {        if(stoplevel!=OrderStopLoss())           {           OrderModify(OrderTicket(),OrderOpenPrice(),stoplevel,OrderTakeProfit(),0,CLR_NONE);           }        }     }         }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

}

void StandardStopsForLongs()
{
double stoplevel=0;
int orderscroll;
int totalshorts=CountLongPositions();
int totalorders=OrdersTotal();
if(totalshorts>1)
{
//scroll to find the lowest stop
for(orderscroll=0;orderscroll<totalorders;orderscroll++)
{
OrderSelect(orderscroll,SELECT_BY_POS,MODE_TRADES);
if((OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber)&&((OrderType()==OP_BUY)))
{
if(OrderStopLoss()>stoplevel)
{
stoplevel=OrderStopLoss();
}
}
}

  //scroll to set the stops  for(orderscroll=0;orderscroll<totalorders;orderscroll++)     {     OrderSelect(orderscroll,SELECT_BY_POS,MODE_TRADES);     if((OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumber)&&((OrderType()==OP_BUY)))        {        if(stoplevel!=OrderStopLoss())           {           OrderModify(OrderTicket(),OrderOpenPrice(),stoplevel,OrderTakeProfit(),0,CLR_NONE);           }        }     }         }
举报

评论 使用道具

下一篇 : 黄金走势

精彩评论42

mydiis
DDD
| 发表于 2021-6-21 23:06:50 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

wangddtt
CC
| 发表于 2021-6-21 23:47:41 | 显示全部楼层
要看懂不容易呀
举报

点赞 评论 使用道具

巴比伦雄鹰
D
| 发表于 2021-6-21 23:54:45 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

猎鲸狐
C
| 发表于 2021-9-10 08:30:46 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

zhzhp666
DDD
| 发表于 2021-9-10 08:59:31 | 显示全部楼层
海龟主要做趋势
举报

点赞 评论 使用道具

wangdehang
DDD
| 发表于 2021-9-10 09:06:09 | 显示全部楼层
海龟主要做趋势,现在测试好像是亏损的
举报

点赞 评论 使用道具

巴比伦雄鹰
D
| 发表于 2021-9-10 10:44:16 | 显示全部楼层
关注
举报

点赞 评论 使用道具

古希腊恶人
D
| 发表于 2021-9-10 12:21:33 | 显示全部楼层
学习学习
举报

点赞 评论 使用道具

zhaozhen0224
DD
| 发表于 2021-9-10 12:26:21 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

cgd998
DD
| 发表于 2021-9-13 07:15:01 | 显示全部楼层
绝对的大爱无疆,谢谢分享
举报

点赞 评论 使用道具

668
DDD
| 发表于 2021-11-17 01:37:16 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

chenyu
DD
| 发表于 2021-11-17 16:18:49 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

qxj9527
D
| 发表于 2021-12-17 15:02:16 | 显示全部楼层
要看懂不容易呀
举报

点赞 评论 使用道具

Figo123456
DD
| 发表于 2021-12-24 15:20:56 | 显示全部楼层
怎么报错呢,可以包装一下吗?
举报

点赞 1 评论 使用道具

交易者
DDD
| 发表于 2022-1-8 16:43:29 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

stephen486
DD
| 发表于 2022-4-6 23:19:00 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

无名小卒
D
| 发表于 2022-4-6 23:26:43 | 显示全部楼层
有用法介绍不
举报

点赞 评论 使用道具

sdsdsw555
D
| 发表于 2022-4-21 17:49:09 | 显示全部楼层
走过路过不要错过
举报

点赞 评论 使用道具

daerwushen
DD
| 发表于 2022-4-21 20:01:49 | 显示全部楼层
看看。。学习下。。。
举报

点赞 评论 使用道具

123下一页
发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册

天眼云VPS
简体中文
繁體中文
English(英语)
日本語(日语)
Deutsch(德语)
Русский язык(俄语)
بالعربية(阿拉伯语)
Türkçe(土耳其语)
Português(葡萄牙语)
ภาษาไทย(泰国语)
한어(朝鲜语/韩语)
Français(法语)