Robot Example 1 – Random Entries
Here is the GFT CTL source code for our first example robot, which uses random entries and fixed take profit and stop loss levels.
//+------------------------------------------------------------------+
//| GuruEx01.ctl |
//| Copyright © 2009, Marketing Dreams Ltd. All Rights Reserved. |
//| http://trading-gurus.com |
//| |
//| GuruTrader™ example 1 |
//| Version 1.0 |
//| |
//| About as simple a "robot" as it is possible to produce |
//| Despite its simplicity it still manages to "predict the future" |
//| with 100% accuracy.... |
//| ....in backtesting EUR/USD on one of my demo accounts |
//| between January 5th 2009 and April 11th 2009 |
//| |
//| Wealth Warning! This expert is for educational purposes only. |
//| It should NEVER be used on a live account. Past performance is |
//| in no way indicative of future results! |
//+------------------------------------------------------------------+
strategy GuruEx01;
input ProfitTarget=100, StopLoss=1000, Lots = 1, FixedSpread = 2;
vars CurrBid(number), PrevBid(number), LastIndex(number), FirstIndex(number), Entry(number), Stop(number), Limit(number);
begin
FirstIndex := front(close);
LastIndex := back(close);
if ((LastIndex - FirstIndex) < 1) then return; PrevBid := close[LastIndex - 1]; CurrBid := close[LastIndex]; if (positionvolume() = 0) then begin cancel_all_limits(); cancel_all_stops(); if (CurrBid > PrevBid) then begin
buy(Lots);
Entry := CurrBid + FixedSpread * 0.0001;
Limit := Entry + ProfitTarget * 0.0001;
Stop := Entry - StopLoss * 0.0001;
limit_sell(Lots, Limit);
stop_sell(Lots, Stop);
print("Long at " + timestamptostr(Timestamp[LastIndex]) + ", Price: " + numbertostring(Entry) + ", Target: " + numbertostring(Limit) + ", Stop: " + numbertostring(Stop));
end
else if (CurrBid < PrevBid) then begin
sell(Lots);
Entry := CurrBid;
Limit := Entry - ProfitTarget * 0.0001;
Stop := Entry + StopLoss * 0.0001;
limit_buy(Lots, Limit);
stop_buy(Lots, Stop);
print("Short at " + timestamptostr(Timestamp[LastIndex]) + ", Price: " + numbertostring(Entry) + ", Target: " + numbertostring(Limit) + ", Stop: " + numbertostring(Stop));
end;
end;
end.
Leave a Comment


Comments on Robot Example 1 – Random Entries
Hello
it returns some errors when compiling in chartstudio.
Could you fix it?
THANKS
Hi Math,
I tried compiling it on my own version of Chart Studio (version 1.0.39.14) and it built and installed fine. Then I tried it on a completely fresh install of DealBook/ChartStudio, and it complained about a missing timestamptostr module.
I don't know if that's the problem you encountered, but can we continue this conversation over on the forum now?
Jim