بسم الله الرحمن الرحيم
السلام عليكم ورحمه الله وبركاته
استاذ سمير يوجد استراتيجه جافا خاصه بمنصه دوكاس كوبي بنك JForex واريد تحويلها لأكسبيرت يعمل على منصات الميتاتريدر ،، ارجو منك الاطلاع عليها واخباري ان كان بالأمكان تحويلها ام لأ ،،وشكرا جزيلا لك ولأحلى منتدى بووووووووووووووووووووووورصات
الاستراتيجه هي
package jforex;
import java.util.*;
import com.dukascopy.api.*;
public class airadopted implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT 0"));
// Strategy state flags
private int isFirstStep=0;
private double firstStepTime=0;
private double firstStepBid=0;
private boolean flipflop=true;
// Order settings
private double TP=50;
private double SL=50;
// Strategy settings
private double timeDelay=5;
private double timeWindow=10;
private double priceDelta=0.0005;
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.context = context;
this.indicators = context.getIndicators();
this.userInterface = context.getUserInterface();
// For remote server execution
Set subscribedInstruments = context.getSubscribedInstruments();
subscribedInstruments.add(Instrument.EURUSD);
context.setSubscribedInstruments(subscribedInstrum ents);
}
public void onAccount(IAccount account) throws JFException {}
public void onMessage(IMessage message) throws JFException {}
public void onStop() throws JFException {}
public void onTick(Instrument instrument, ITick tick) throws JFException
{
IOrder CurrentOrder;
IBar prevBar, currBar, prevDayBar;
double spread, diffPrevBar;
boolean cantBuy, cantSell;
// Set current time (backtesting)
calendar.setTimeInMillis(tick.getTime());
// Order already opened?
CurrentOrder=getCurrentOrder();
if (CurrentOrder==null && isFirstStep==0 && !isEnfOfTradingWeek())
{
// Sometimes error happens in accessing history bars (usually at 0:00 and 17:00 GMT)
// So try/catch is for this
try
{
currBar = history.getBar(instrument, Period.FIVE_MINS, OfferSide.BID, 0);
prevBar = history.getBar(instrument, Period.FIVE_MINS, OfferSide.BID, 1);
}
catch (Exception e)
{
return;
}
spread=tick.getAsk()-tick.getBid();
diffPrevBar=prevBar.getHigh()-prevBar.getLow();
if (spread < 0.00004 && diffPrevBar < 0.0030)
{
if (tick.getBid() >= (4*prevBar.getHigh()+prevBar.getLow())/5 && tick.getBid() <= prevBar.getHigh())
{
isFirstStep=1;
firstStepTime=tick.getTime();
firstStepBid=tick.getBid();
}
else if (tick.getBid() <= (4*prevBar.getLow()+prevBar.getHigh())/5 && tick.getBid() >= prevBar.getLow())
{
isFirstStep=-1;
firstStepTime=tick.getTime();
firstStepBid=tick.getBid();
}
}
}
else if (CurrentOrder==null && isFirstStep!=0 && !isEnfOfTradingWeek())
{
// Sometimes error happens in accessing history bars (usually at 0:00 and 17:00 GMT)
// So try/catch is for this
try
{
currBar = history.getBar(instrument, Period.FIVE_MINS, OfferSide.BID, 0);
prevBar = history.getBar(instrument, Period.FIVE_MINS, OfferSide.BID, 1);
prevDayBar = history.getBar(instrument, Period.DAILY, OfferSide.BID, 1);
}
catch (Exception e)
{
return;
}
diffPrevBar=prevBar.getHigh()-prevBar.getLow();
double prevDayRange=Math.abs(prevDayBar.getOpen()-prevDayBar.getClose());
if (prevDayRange<0.0105 && prevDayRange>0.0010) flipflop=false;
else flipflop=true;
if (tick.getBid()-firstStepBid > priceDelta && tick.getTime()-firstStepTime>1000*60*timeDelay ) // Buy
{
if (flipflop)
BuyMarket (instrument, engine, TP, SL, getLots(10, SL, tick.getAsk()), tick);
else
SellMarket (instrument, engine, SL, TP, getLots(10, TP, tick.getBid()), tick);
isFirstStep=0;
}
else if (tick.getBid()-firstStepBid < -priceDelta && tick.getTime()-firstStepTime>1000*60*timeDelay ) // Sell
{
if (flipflop)
SellMarket (instrument, engine, TP, SL, getLots(10, SL, tick.getBid()), tick);
else
BuyMarket (instrument, engine, SL, TP, getLots(10, TP, tick.getAsk()), tick);
isFirstStep=0;
}
else if(tick.getTime()-firstStepTime>1000*60*timeWindow) isFirstStep=0;
}
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException
{
IOrder CurrentOrder;
// Set current time (backtesting)
calendar.setTimeInMillis(askBar.getTime());
// Process market state if this is 5 minute bar
if (period == Period.FIVE_MINS)
{
CurrentOrder=getCurrentOrder();
if (CurrentOrder != null)
{
// Close position if approaching end of week
// TODO: reduce/close position based on current profit, end if 21 GMT is reached
int DayOfWeek=calendar.get(Calendar.DAY_OF_WEEK);
int Hour=calendar.get(Calendar.HOUR_OF_DAY);
int Min=calendar.get(Calendar.MINUTE);
//This is changing from JForex version to version so needs to be checked often...
if (DayOfWeek==Calendar.FRIDAY && Hour==17 && Min>=54)
{
CurrentOrder.close();
}
}
}
}
// Money Management
protected double getLots(int Risk, double StopLevelPips, double Price)
{
double Balance, Leverage, FreeTradingLine;
double Lots, maxLots;
Balance=context.getAccount().getEquity();
Leverage=context.getAccount().getLeverage();
FreeTradingLine=Balance*Leverage;
Lots=FreeTradingLine*0.8/1000000/(Price+StopLevelPips*0.0001)*Risk/10;
return Math.min(8.88, Lots);
}
// Helper method for creating Order Label
protected String getLabel(Instrument instrument)
{
String label = instrument.name();
long time = new java.util.Date().getTime();
label = label.substring(0, 2) + label.substring(3, 5);
label = label + time;
label = label.toLowerCase();
return label;
}
// Simplified call to Sell at market Order - predefined max. 3 pips slippage
protected void SellMarket(Instrument instrument, IEngine engine, double LimitPips, double StopPips, double Lots, ITick tick) throws JFException
{
engine.submitOrder(this.getLabel(instrument), instrument, IEngine.OrderCommand.SELL, Lots,
0, 3,
this.TruncateTo5Decimals(tick.getBid()+instrument. getPipValue()*StopPips),
this.TruncateTo5Decimals(tick.getBid()-instrument.getPipValue()*LimitPips));
}
// Simplified call to Buy at market Order - predefined max. 3 pips slippage
protected void BuyMarket(Instrument instrument, IEngine engine, double LimitPips, double StopPips, double Lots, ITick tick) throws JFException
{
engine.submitOrder(this.getLabel(instrument), instrument, IEngine.OrderCommand.BUY, Lots,
0, 3,
this.TruncateTo5Decimals(tick.getAsk()-instrument.getPipValue()*StopPips),
this.TruncateTo5Decimals(tick.getAsk()+instrument. getPipValue()*LimitPips));
}
// Get currently opened order
protected IOrder getCurrentOrder() throws JFException
{
IOrder CurrentOrder=null;
// Find FILLED order - in this strategy only one should exist
for (IOrder order : engine.getOrders())
{
if (order.getState() == IOrder.State.FILLED)
{
CurrentOrder=order;
break;
}
}
return CurrentOrder;
}
protected double TruncateTo5Decimals(double DecimalNumber)
{
return Math.round((DecimalNumber+0.000005)*100000.0)/100000.0;
}
protected boolean isEnfOfTradingWeek()
{
int DayOfWeek=calendar.get(Calendar.DAY_OF_WEEK);
int Hour=calendar.get(Calendar.HOUR_OF_DAY);
// TODO: 13 is specific for this strategy
if (DayOfWeek==Calendar.FRIDAY && Hour>=13) return true;
else return false;
}
}
التوقيع
دعاء قضاء الدين وجلب الرزق
" اللهم مالك الملك تؤتى الملك من تشاء وتنزع الملك ممن تشاء وتعز من تشاء وتذل من تشاء بيدك الخير إنك على كل شىء قدير "
تولج الليل في النهار وتولج النهار في الليل وتخرج الحي من الميت وتخرج الميت من الحي وترزق من تشاء بغير حساب
رحمن الدنيا والآخره تعطيهم من تشاء وتمنع منهما من تشاء إرحمنى رحمه تغنينى بها عن رحمة من سواك .