거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Twitter에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
당사 팬 페이지에 가입하십시오
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
- 조회수:
- 3107
- 평가:
- 게시됨:
- 2024.05.28 20:17
- 업데이트됨:
- 2024.05.28 20:19
-
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동
I. Condition Buy-Sell
2. Backtest
1. Main function for calculate lot size
//+------------------------------------------------------------------+ //| caculate lot sisze Function | //+------------------------------------------------------------------+ double calculate_lotsize(double sl, double price) { double lots=0.; double lotstep= SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP); double ticksize = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE); double tickvalue = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE); double balance= AccountInfoDouble(ACCOUNT_BALANCE); double point= SymbolInfoDouble(_Symbol,SYMBOL_POINT); //double loss=MathRound((MathAbs(price-sl)/ ticksize) * ticksize ); double loss=MathAbs(price-sl)/point; m_symbol.NormalizePrice(loss); double Risk= initial_risk*balance;if(loss!=0) { lots=MathAbs(Risk/loss); lots=MathFloor(lots/lotstep)*lotstep; } lots=MathMax(lots,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN)); lots=MathMin(lots,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX)); return lots; }
2. Trailling and Count Position
//+------------------------------------------------------------------+ //|Count position and Trailling Functiom | //+------------------------------------------------------------------+ void count_position(int &count_buy, int &count_sell) { count_buy=0; count_sell=0; int total_postion=PositionsTotal(); double cp=0.0, op=0.0, sl=0.0,tp=0.0; ulong ticket=0.0; for ( int i=total_postion-1; i>=0; i--) { if(m_position.SelectByIndex(i)) { if(m_position.Symbol()==_Symbol && m_position.Magic()== m_magicnumber) cp=m_position.PriceCurrent();op=m_position.PriceOpen();sl=m_position.StopLoss();tp=m_position.TakeProfit();ticket=m_position.Ticket(); { if(m_position.PositionType()== POSITION_TYPE_BUY) { count_buy++; double Traill= cp-ExtTraill_Stop; if(cp>sl+ExtTraill_Step && Traill>sl) { trade.PositionModify(ticket,Traill,tp); } } if(m_position.PositionType()== POSITION_TYPE_SELL) { count_sell++; double Traill= cp+ExtTraill_Stop; if(cp<sl-ExtTraill_Step && Traill<sl) { trade.PositionModify(ticket,Traill,tp); } } } } } }
3. Only buy or sell at new candle function
//+------------------------------------------------------------------+ //|Only buy or sell at new candle | //+------------------------------------------------------------------+ datetime mprevBar; bool OpenBar(string symbol) { datetime CurBar=iTime(symbol,timeframe,0); if( CurBar==mprevBar) { return false; } mprevBar=CurBar; return true; }
4. Drawn suport and resistance
void Drawline(string name, color Color, double price) { if(ObjectFind(0,name)<0) { ResetLastError();; } if(!ObjectCreate(0,name,OBJ_HLINE,0,0,price)) { return; } // Setup color for object ObjectSetInteger(0,name,OBJPROP_COLOR,Color); // Setup color for object ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DASHDOT); // Setup color for object ObjectSetInteger(0,name,OBJPROP_WIDTH,2); if(!ObjectMove(0,name,0,0,price)) { return; } ChartRedraw(); }
II. Main function void Ontick
//+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(OpenBar(Symbol())) { //+------------------------------------------------------------------+ //| // Candle declaration | //+------------------------------------------------------------------+ double High[],Low[],open[],close[]; ArraySetAsSeries(High,true);ArraySetAsSeries(Low,true);ArraySetAsSeries(close,true);ArraySetAsSeries(open,true); CopyHigh(Symbol(),timeframe,0,1000,High); CopyLow(Symbol(),timeframe,0,1000,Low); CopyOpen(_Symbol,timeframe,0,100,open); CopyClose(_Symbol,timeframe,0,100,close); // Highest high and lowest low declaration int highest= ArrayMaximum(High,HL_shift,HL_period); int lowest= ArrayMinimum(Low,HL_shift,HL_period); double HH= High[highest]; Drawline(" Kháng Cự ", clrRed,HH); double LL= Low[lowest]; Drawline(" hỗ trợ ", clrBlue,LL); // Moving average declaration CopyBuffer(Handle_MA,0,0,100,MA_Filter); ArraySetAsSeries(MA_Filter,true); //| Broker parameter double point = SymbolInfoDouble(_Symbol,SYMBOL_POINT); double ask= SymbolInfoDouble(_Symbol,SYMBOL_ASK); double bid= SymbolInfoDouble(_Symbol,SYMBOL_BID); double spread=ask-bid; double stoplevel= (int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL); int freezerlevel= (int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_FREEZE_LEVEL); // Count bjuy and count sell int count_buy=0; int count_sell=0; count_position(count_buy,count_sell); // Main condition for buy and sell if(count_buy==0) { if(ask>(HH) && High[highest] > MA_Filter[highest] ) { double entryprice= ask; double sl = LL; double tp = entryprice +Exttakeprofit; double lotsize = calculate_lotsize(sl,entryprice); if( bid-sl>stoplevel && tp-bid>stoplevel&& CheckVolumeValue(lotsize) ) { trade.Buy(lotsize,_Symbol,entryprice,sl,tp, " Buy Mr Tan "); } } } if(count_sell==0) { if(bid<(LL) && Low[lowest] < MA_Filter[lowest]) { double entryprice= bid; double sl = HH; double tp = entryprice -Exttakeprofit; double lotsize = calculate_lotsize(sl,entryprice); if( sl-ask>stoplevel && ask-tp>stoplevel&& CheckVolumeValue(lotsize) ) { trade.Sell(lotsize,_Symbol,entryprice,sl,tp, " Sell Mr Tan "); } } } } }
![Delete all objects on chart (main window and sub window) with drag and drop](https://c.mql5.com/i/code/script.png)
It will delete all objects on the chart when the compiled executable is dragged onto the chart
![Trap News MT5](https://c.mql5.com/i/code/script.png)
Script For Trap News High Impact
![Trailing stop tutorial using ATR indicator](https://c.mql5.com/i/code/expert.png)
Trailing stop tutorial using ATR indicator
![Lesson 7 Price action Ket hop Volume VSA](https://c.mql5.com/i/code/expert.png)
This is a lesson on trading using price action combined with volume.