| View previous topic :: View next topic |
| Author |
Message |
pthomas82
Joined: 11 Aug 2010 Posts: 45
|
Posted: Tue Jun 07, 2011 8:55 am Post subject: help Please |
|
|
Hi Guys,
Im looking for some help - currently im learning delphi and I throught it try code up something simple like when an indicator hits a certain level the script places a buy order, and if an indicator hits another level it places a sell order.
This code compiles ok - but it doesnt place buy and sell orders.
Can some kind member of this community point out where I have gone wrong =)
Thanks in advance,
Pete.
| Code: | library CCITRY;
uses
SysUtils, Classes, StrategyInterfaceUnit, TechnicalFunctions;
var
Currency: PChar = nil;
TimeFrame: integer;
LotSize: double;
CCI1: integer;
CCIUPPER: integer;
CCILOWER: integer;
OrderHandle: integer;
OrderStyle: TTradePositionType;
OpenTime: TDateTime;
procedure InitStrategy; stdcall;
begin
StrategyShortName('CCITRY');
StrategyDescription('CCI level strategy');
RegOption('Currency', ot_Currency, Currency);
ReplaceStr(Currency, 'EURUSD');
RegOption('Timeframe', ot_Timeframe, TimeFrame);
TimeFrame := PERIOD_M1;
RegOption('LotSize', ot_Double, LotSize);
SetOptionDigits('LotSize', 1);
lotSize := 0.1;
RegOption('CCI1', ot_Integer, CCI1);
CCI1 := 30;
RegOption('CCIUPPER', ot_Integer, CCIUPPER);
CCIUPPER := 250;
RegOption('CCILOWER', ot_Integer, CCILOWER);
CCIUPPER := -250;
end;
procedure DoneStrategy; stdcall;
begin
FreeMem(Currency)
end;
procedure ResetStrategy; stdcall;
begin
OrderHandle := -1
end;
procedure GetSingleTick; stdcall;
var
CCI: Double;
begin
if Symbol <> string(Currency) then exit;
SetCurrencyAndTimeframe(Symbol, TimeFrame);
CCI := GetIndicatorValue(CCI1, 1,0);
if (OrderHandle = 0) and (CCI > CCIUPPER) then
begin
SendInstantOrder(Symbol, op_Buy, LotSize, Ask - 20*Point, Ask + 50*Point, '',0, OrderHandle);
OrderStyle := tp_Buy;
OpenTime := Time(0)
end;
if (OrderHandle = 0) and (CCI < CCILOWER) then
begin
SendInstantOrder(Symbol, op_Sell, LotSize, Ask + 20*Point, Ask - 50*Point, '', 0, OrderHandle);
OrderStyle := tp_Sell;
OpenTime := Time(0)
end;
end;
exports
InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick,
ReplaceStr;
end. |
|
|
| Back to top |
|
 |
FT Support
Joined: 11 Jul 2009 Posts: 901
|
Posted: Tue Jun 07, 2011 7:28 pm Post subject: |
|
|
Hello,
It seems that the problem is:
- you have "OrderHandle := -1" in "ResetStrategy" procedure
- you also have "if (OrderHandle = 0)" condition which will never be "true" because OrderHandle is always -1 _________________ Check our other products here:
www.fx-metropolis.com
www.forexcopier.com |
|
| Back to top |
|
 |
pthomas82
Joined: 11 Aug 2010 Posts: 45
|
Posted: Tue Jun 07, 2011 8:33 pm Post subject: |
|
|
Awesome, thanks support! I'll get trying that. Also any code I build i'll throw up here. I believe the community will find it easier to learn with more code to copy from!
Thanks for your help! |
|
| Back to top |
|
 |
pthomas82
Joined: 11 Aug 2010 Posts: 45
|
Posted: Wed Jun 08, 2011 9:55 am Post subject: |
|
|
Ok - so I got it working, a mixture of problems - the main one was not creating the indicator.
So below is the code for shareing! Basically it just goes long or short when the CCI hits a certain level.
| Code: | library CCIOPTIONS;
uses
SysUtils,
Classes,
StrategyInterfaceUnit,
TechnicalFunctions;
var
Currency: PChar = nil;
TimeFrame: integer;
LotSize: double;
CCICURRENT: Double;
CCI: integer;
STOPLOSS: Integer;
TAKEPROFIT: Integer;
CCIUPPER: Integer;
CCILOWER: Integer;
OrderHandle: integer;
OrderStyle: TTradePositionType;
OpenTime: TDateTime;
procedure InitStrategy; stdcall;
begin
StrategyShortName('CCI OPTIONS');
StrategyDescription('CCI level strategy');
RegOption('Currency', ot_Currency, Currency);
ReplaceStr(Currency, 'EURUSD');
RegOption('Timeframe', ot_Timeframe, TimeFrame);
TimeFrame := PERIOD_M1;
RegOption('LotSize', ot_Double, LotSize);
SetOptionDigits('LotSize', 1);
lotSize := 0.1;
RegOption('STOPLOSS (PIPS)', ot_Integer, STOPLOSS);
STOPLOSS := 20;
RegOption('TAKE PROFIT (PIPS)', ot_Integer, TAKEPROFIT);
TAKEPROFIT := 20;
RegOption('CCI UPPER BUY LEVEL', ot_Integer, CCIUPPER);
CCIUPPER := 200;
RegOption('CCI LOWER SELL LEVEL', ot_Integer, CCILOWER);
CCILOWER := 200;
end;
procedure DoneStrategy; stdcall;
begin
FreeMem(Currency)
end;
procedure ResetStrategy; stdcall;
begin
OrderHandle := -1;
CCI := CreateIndicator('EURUSD', Period_M1, 'CCI', '100');
end;
procedure GetSingleTick; stdcall;
begin
if Symbol <> string(Currency) then exit;
SetCurrencyAndTimeframe(Symbol, TimeFrame);
CCICURRENT := GetIndicatorValue(CCI, 0, 1);
if (OrderHandle = -1) and (CCICURRENT >CCIUPPER) then
begin
SendInstantOrder(Symbol, op_Buy, LotSize, 0, 0, '',0, OrderHandle);
OrderStyle := tp_Buy;
OpenTime := Time(0)
end;
if (OrderHandle = -1) and (CCICURRENT <-CCILOWER) then
begin
SendInstantOrder(Symbol, op_Sell, LotSize, 0, 0, '', 0, OrderHandle);
OrderStyle := tp_Sell;
OpenTime := Time(0)
end;
if OrderSelect(0, SELECT_BY_POS, MODE_TRADES) THEN
if (OrderHandle <> -1) and (OrderProfitPips >= TAKEPROFIT) or (OrderProfitPips <=-STOPLOSS) then
begin
CloseOrder(OrderHandle);
OrderHandle := -1;
End;
end;
exports
InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick,
ReplaceStr;
end. |
Now one thing I can not do is get the CCI value (in this case 100) as a variable
| Code: | | CCI := CreateIndicator('EURUSD', Period_M1, 'CCI', '100'); |
I've tried defining a variable for '100' but, the problem is that the variable is an integer and the code needs a string. Anyone have any ideas? |
|
| Back to top |
|
 |
pthomas82
Joined: 11 Aug 2010 Posts: 45
|
Posted: Wed Jun 08, 2011 11:49 am Post subject: |
|
|
Also, How can i look back to the previous bar,
for example: If (CCI value 1
bar ago < 200) and (CCI value current bar > 200) then ... ... ...
Thanks again  |
|
| Back to top |
|
 |
FT Support
Joined: 11 Jul 2009 Posts: 901
|
|
| Back to top |
|
 |
pthomas82
Joined: 11 Aug 2010 Posts: 45
|
Posted: Fri Jun 10, 2011 12:08 pm Post subject: |
|
|
Thanks again Mike,
IM learning heaps every day! Your software is great and the language seems pretty easy! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|