MT5一键开仓脚本。包含两个脚本,一键开多单和一键开空单。可以设置魔术数,手数,止损点数,止盈点数,注释。 参数如下: input ulong Magic = 123; //魔术数input double Lots = 0.1; //手数input ulong StopLoss = 0; //止损点数input ulong TakeProfit = 0; //止盈点数input string Comms = ""; //单子注释
#property copyright "Copyright 2021,fxMeter"#property link "https://www.mql5.com/zh/users/fxmeter"#property version "1.00"#property script_show_inputs#include <Trade\Trade.mqh>input ulong Magic = 123; //魔术数input double Lots = 0.1; //手数input ulong StopLoss = 0; //止损点数input ulong TakeProfit = 0; //止盈点数input string Comms = ""; //单子注释CTrade trade;//+------------------------------------------------------------------+//| Script program start function |//+------------------------------------------------------------------+void OnStart(){//--- trade.SetExpertMagicNumber(Magic); trade.SetDeviationInPoints(ULONG_MAX); trade.SetTypeFillingBySymbol(Symbol());//--- double sl = 0.0,tp = 0.0; double now = SymbolInfoDouble(Symbol(),SYMBOL_BID); if(StopLoss > 0) { sl = now + StopLoss * Point(); if(sl < 0)sl = 0.0; } sl = NormalizeDouble(sl,Digits()); if(TakeProfit > 0) { tp = now - TakeProfit * Point(); if(tp < 0)tp = 0.0; } tp = NormalizeDouble(tp,Digits()); trade.Sell(Lots,NULL,0.0,sl,tp,Comms);}//+------------------------------------------------------------------+#property copyright "Copyright 2021,fxMeter"#property link "https://www.mql5.com/zh/users/fxmeter"#property version "1.00"#property script_show_inputs#include <Trade\Trade.mqh>input ulong Magic = 123; //魔术数input double Lots = 0.1; //手数input ulong StopLoss = 0; //止损点数input ulong TakeProfit = 0; //止盈点数input string Comms = ""; //单子注释CTrade trade;//+------------------------------------------------------------------+//| Script program start function |//+------------------------------------------------------------------+void OnStart(){//--- trade.SetExpertMagicNumber(Magic); trade.SetDeviationInPoints(ULONG_MAX); trade.SetTypeFillingBySymbol(Symbol());//--- double sl = 0.0,tp = 0.0; double now = SymbolInfoDouble(Symbol(),SYMBOL_ASK); if(StopLoss > 0) { sl = now - StopLoss * Point(); if(sl < 0)sl = 0.0; } sl = NormalizeDouble(sl,Digits()); if(TakeProfit > 0) { tp = now + TakeProfit * Point(); if(tp < 0)tp = 0.0; } tp = NormalizeDouble(tp,Digits()); trade.Buy(Lots,NULL,0.0,sl,tp,Comms);} |