작업 종료됨
실행 시간 10 시간
명시
MQL4 - Get Price Difference between Position and current price
Basically I want the following code
If i got 0 position, bool validGap = 0;
Then it open e.g UJ long at 99.00
Now i got 1 order
UJ long at 99.00
My setting is gap 25 Points
if UJ goes to 99.25, i want to open 1 more position (add to winner)
or if UJ goes to 98.75 , I want to open 1 more position ( add to loser )
Take note the amount of digits or what symbol I playing need to be dynamic, no hardcoding.
My current code is something like this, however the EA keep open position despite there is no 25 * one Pip gap
Consider my gapTrade is value 25
double SL,TP,onePip; int Ticket; onePip = 0.00; if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.00001) onePip = 0.0001; else if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.001) onePip = 0.01; else onePip = MarketInfo(OrderSymbol(), MODE_POINT); /***********************************/ //check if price match double currentPrice; currentPrice = MarketInfo(Symbol(),MODE_BID); bool validGap = false; // Initial - Not Okay. double minValue,maxValue,priceDiff; priceDiff = 0.00; minValue = 9999.0; for (int ii=OrdersTotal()-1 ; ii>=0 ; ii--) { if (!OrderSelect(ii,SELECT_BY_POS)) continue; if (OrderSymbol() == Symbol()) if (OrderOpenPrice() > maxValue) { maxValue = OrderOpenPrice(); } if (OrderOpenPrice() < minValue) { minValue = OrderOpenPrice(); } } if(direction=="SELL") { priceDiff = currentPrice - maxValue; if( priceDiff > onePip*gapTrade) { validGap = true; } } if(direction=="BUY") { priceDiff = minValue - currentPrice; //We use max value if( priceDiff > onePip*gapTrade) { validGap = true; } } //Check if best trade in a buy is in profit /* ADD NEW POSITION TO A WINNING 1 */ if(direction=="BUY") { priceDiff = currentPrice - maxValue; if( priceDiff > onePip*gapTrade) { validGap = true; } } if(direction=="SELL") { priceDiff = minValue - currentPrice; if( priceDiff > onePip*gapTrade) { validGap = true; } }
응답함
1
등급
프로젝트
150
29%
중재
9
44%
/
11%
기한 초과
46
31%
무료
2
등급
프로젝트
2820
80%
중재
156
22%
/
43%
기한 초과
487
17%
무료
3
등급
프로젝트
46
54%
중재
3
67%
/
0%
기한 초과
14
30%
무료
4
등급
프로젝트
809
73%
중재
30
33%
/
37%
기한 초과
194
24%
무료
5
등급
프로젝트
144
46%
중재
20
40%
/
20%
기한 초과
32
22%
무료
6
등급
프로젝트
1458
72%
중재
122
29%
/
48%
기한 초과
356
24%
무료
게재됨: 3 기고글
프로젝트 정보
예산
10 - 20 USD
기한
에서 1 로 2 일