I put the 'global variables' in the wrong location (within GetSingleTick). I should've put it in the beginning of the library coding following the external variables.
Hello, Mike, or any experienced programmer:
Could you please take a quick look at my case? it should be an easy fix but i just don't know how or why. although my code is long, my question seems in fact simple.
I attached the complete code below, it is an strategy I coded in Delphi 7. When I compile, I keep getting "undeclared" errors. I don't understand these errors, since I do declare them in either 'GetSingleTick' or the routines: for example, if you try to compile the attached code, the four errors below will be on the top 4 errors:
[Error]: Undeclared identifier: 'CheckPrevBids'
[Error]: Undeclared identifier: 'CloseAllTradesIfNeeded'
[Error]: Undeclared identifier: 'OpenPhantomTrades'
[Error]: Undeclared identifier: 'CalPhantomPL'
but clearly in my code, you can see that I declared these procedure/functions.
Code: Select all
library RC_4questions;
uses
SysUtils, DateUtils, StrategyInterfaceUnit, TechnicalFunctions;
//external parameters
var
SpecificLot: double = 0.01;
FreeLot: double = 0.01;
ProfitPct: double = 1.0;
FailurePct: double = 1.0;
MagicNumber: integer= 912;
RunFreeLot: boolean= true;
Pair1: PChar = 'GBPUSD';
Pair2: PChar = 'EURJPY';
Pair3: PChar = 'AUDUSD';
Pair4: PChar = 'NUDJPY';
Pair5: PChar = 'EURAUD';
procedure InitStrategy; stdcall;
begin
StrategyShortName('RepeatStrategy');
StrategyDescription('Repeat strategy that does nothing');
RegOption('Specific Lot', ot_Double, SpecificLot);
RegOption('Free Lot', ot_Double, FreeLot);
RegOption('Profit%', ot_Double, ProfitPct);
RegOption('Failure%', ot_Double, FailurePct);
RegOption('Magic Number', ot_Integer, MagicNumber);
RegOption('Pair 1', ot_String, Pair1);
RegOption('Pair 2', ot_String, Pair2);
RegOption('Pair 3', ot_String, Pair3);
RegOption('Pair 4', ot_String, Pair4);
RegOption('Pair 5', ot_String, Pair5);
end;
procedure DoneStrategy; stdcall;
begin
end;
procedure ResetStrategy; stdcall;
begin
end;
// Found a New Bar
function NewBar(timeframe:integer): boolean;
var
found: boolean;
begin
found := true;
NewBar := found; // Or use 'Result'
end;
procedure GetSingleTick; stdcall;
var
sym: array[1..10] of Pchar;
pairAsk: array[1..5] of Double;
pairBid: array[1..5] of Double;
PhantomPL: array[1..10] of Double;
PairPL: array[1..10] of Double;
PairBuys: array[1..10] of integer;
PairSells: array[1..10] of integer;
prevBid: array[1..10] of double;
prevAsk: array[1..10] of double;
pairPoint: array[1..10] of double;
pairTickVal:array[1..10] of double;
SymbolMarks:array[1..10] of boolean;
i, OrderSendResult, SysTF, CutInterval: integer;
NOofSells, NOofBuys, TotalTrades: integer;
RealPhantomWinnerType, Real2ndPhantomWinnerType: integer;
RealPhantomWinnerTicket, Real2ndPhantomWinnerTicket, BigPhantomWinnerTicket, BigPhantomLoserTicket: integer;
RealPhantomWinnerPL, Real2ndPhantomWinnerPL, BigPhantomWinnerPL, BigPhantomLoserPL: double;
UseLots, DollarProfitTarget, DollarLossFail, RealisedLoss, EAfProfitPeak, EAfLossPeak: double;
CloseAll, PriceChanged, SymbolMarksCleared, SymbolMarked, PhantomsReset, NewBarFormed: boolean;
// 888888 start 888888
begin
PriceChanged := CheckPrevBids();
if TotalTrades > 0 then CloseAllTradesIfNeeded();
OpenPhantomTrades();
CalPhantomPL();
if TotalTrades = 0 then
begin
CloseAll := false;
EAfProfitPeak := 0;
EAfLossPeak := 0;
RealisedLoss := 0;
if Hour(TimeCurrent) < StartHour or Hour(TimeCurrent) > FinishHour then
PhantomsReset := true
else
begin
ResetPhantoms();
PhantomsReset := false;
end
end
AddIfNeeded();
if not CloseAll and ( EAPL>(DollarProfitTarget + Floor(Abs(RealisedLoss))) or (EAPL+RealisedLoss)<DollarLossFail ) then
begin
CloseAll := true;
ResetPhantoms();
end
ExamineUpdatePLfloat();
UpdatePrevBids();
if TotalTrades > 5 then
begin
if TotalTrades <= 9 then CutInterval := 22;
if TotalTrades > 9 and TotalTrades <= 15 then CutInterval := 16;
if TotalTrades > 15 and TotalTrades <= 22 then CutInterval := 11;
if TotalTrades > 22 then CutInterval := 7;
end
end;
// 888888 start 888888
procedure CloseAllTradesIfNeeded();
var
n: integer;
begin
if PriceChanged and CloseAll then
begin
for n := 0 to OrdersTotal() do
begin
OrderSelect(n,SELECT_BY_POS,MODE_TRADES);
if OrderMagicNumber() = MagicNumber do
begin
if OrderType() = OP_BUY do
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(), MODE_BID),Slippage,White);
if OrderType() = OP_SELL do
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(), MODE_ASK),Slippage,White);
end
end
end
end
function CheckPrevBids(): boolean;
var
n: integer;
begin
for n := 1 to 5 do
begin
if prevAsk[n] <> 0 and prevAsk[n] <> MarketInfo(sym[n], MODE_ASK) then CheckPrevBids := true;
if prevBid[i] <> 0 and prevBid[i] <> MarketInfo(sym[n+5], MODE_BID) then CheckPrevBids := true;
end
end
procedure SetSymbols();
begin
sym[1] := Pair1;
sym[2] := Pair2;
sym[3] := Pair3;
sym[4] := Pair4;
sym[5] := Pair5;
sym[6] := Pair6;
sym[7] := Pair7;
sym[8] := Pair8;
sym[9] := Pair9;
sym[10] := Pair10;
end
procedure OpenPhantomTrades();
var
i: integer;
begin // ??? learn about variable, internal, local, global???
for i:= 1 to 5 do
if pairAsk[i] == 0.0 then
pairAsk[i] := MarketInfo(sym[i], MODE_ASK);
for i:= 1 to 5 do
if pairBid[i] == 0.0 then
pairBid[i] := MarketInfo(sym[i+5], MODE_BID);
end
function SetPoint(aSymbol: string): double;
var
apoint, adigits: double;
begin
adigits := MarketInfo(aSymbol, mode_digits);
if adigits < 4 then
apoint := 0.01;
else
apoint := 0.001;
SetPoint := apoint;
end
function SetTickValue(aSymbol: string, aPoint: double): double;
var
aTickval: double;
begin
if aPoint/10 = MarketInfo(aSymbol, mode_point) then
aTickval := MarketInfo(aSymbol, mode_tickvalue) * 10;
else
aTickval := MarketInfo(aSymbol, mode_tickvalue);
SetTickValue:= aTickval;
end
procedure SetPointsAndTickvalues();
var
n: integer;
begin
for n := 1 to 10 do
begin
pairPoint[n] := SetPoint(sym[n]);
pairTickVal[n] := SetTickValue(sym[n], pairPoint[n]);
end
end
procedure CalcPhantomPL();
var
n: integer;
begin
SetPointsAndTickvalues();
BiggestPhantomWinnerPL = 0.0;
BiggestPhantomWinnerType = 0;
BiggestPhantomWinnerSymbol = '';
BiggestPhantomLoserPL = 0.0;
BiggestPhantomLoserType = 0;
BiggestPhantomLoserSymbol = '';
for n := 1 to 10 do
begin
if pricePoint[n] <> 0 then
begin
if n <=5 then
PhantomPL[n] := (MarketInfo(sym[n], mode_bid) - priceAsk[i])/pairPoint[i];
else
PhantomPL[n] := (priceBid[i] - MarketInfo(sym[n], mode_ask))/pairPoint[i];
PhantomPL[n] := 0.1 * PhantomPL[n] * TickvalArray[n];
if PhantomPL[n] > BigPhantomWinnerPL then
begin
BigPhantomWinnerPL = PhantomPL[n];
BigPhantomWinnerSymbol = sym[n]
if n <= 5 then
BigPhantomWinnerType = 1; // 1 means long
else
BigPhantomWinnerType = 0; // 0 means short
end
if PhantomPL[n] < BigPhantomLoserPL then
begin
BigPhantomLoserPL = PhantomPL[n];
BigPhantomLoserSymbol = sym[n]
if n <= 5 then
BigPhantomLoserType = 1; // 1 means long
else
BigPhantomLoserType = 0; // 0 means short
end
end
end
if BigPhantomWinnerPL > Abs(BigPhantomLoserPL) then
begin
RealPhantomWinnerPL = BigPhantomWinnerPL;
RealPhantomWinnerSymbol = BigPhantomWinnerSymbol;
RealPhantomWinnerType = BigPhantomWinnerType;
end
else
begin
RealPhantomWinnerPL = Abs(BigPhantomLoserPL);
RealPhantomWinnerSymbol = BigPhantomLoserSymbol;
if BigPhantomLoserType = 1 then
RealPhantomWinnerType = 0;
if BigPhantomLoserType = 0 then
RealPhantomWinnerType = 1;
end
// later to add: LocateReal2ndPhantomWinner(RealPhantomWinnerSymbol);
end
procedure ClearSymbolMarks();
var
begin
end
function SymbolMarked(pairsym:PChar): boolean;
var
begin
end
procedure MarkSymbol(pairsym:PChar);
var
begin
end
procedure AddIfNeeded();
var
n: integer;
pairsym: PChar;
begin
if Minute <> 5 and Minute <> 35 then ClearSymbolMarks();
if PriceChanged and CloseAll = false then
begin
PhantomsReset := false;
if SymbolMarked(RealPhantomWinnerSymbol) and ( (SysTF = 60 and Minute = 5) or (SysTF = 30 and (Minute = 5 or Minute = 35)) or (SysTF = 120 and Mod(Hour(),2) = 0 and Minute = 5) or (SysTF = 240 and Mod(Hour(),4) = 0 and Minute = 5)) ) then
begin
for n := 1 to 10 do
begin
pairsym := sym[n];
if pairsym = RealPhantomWinnerSymbol then
begin
if RealPhantomWinnerType = 1 then
OrderSendResult := OrderSend(sym[n],OP_BUY,UseLots,MarketInfo(sym[n], MODE_ASK), Slippage,0,0,WindowExpertName(),MagicNumber,Blue);
if RealPhantomWinnerType = 0 then
OrderSendResult := OrderSend(sym[n],OP_SELL,UseLots,MarketInfo(sym[n], MODE_BID), Slippage,0,0,WindowExpertName(),MagicNumber,Blue);
if OrderSendResult > 0 then MarkSymbol(RealPhantomWinnerSymbol)
else
Alert(WindowExpertName()+" FAILED to buy a REAL " + SymbolArray[i] + ".");
end
end
end
end
end
procedure Count_Trades_PL();
var
n: integer;
begin
NOofSells := 0;
NOofBuys := 0;
TotalTrades := 0;
EAPL := 0;
BiggestWinnerPL := 0;
BiggestWinnerTicket := 0;
BiggestWinnerType := '';
BiggestWinnerSymbol := '';
BiggestLoserPL := 0;
BiggestLoserTicket := 0;
BiggestLoserType := '';
BiggestLoserSymbol := '';
for n := 0 to OrdersTotal - 1 do
begin
OrderSelect(n, Select_By_Pos, mode_trades)
if OrderMagicNumber = MagicNumber and OrderLots = SpecificLot then
begin
EAPL = EAPL + OrderProfit;
TotalTrades = TotalTrades + 1;
if OrderProfit > BiggestWinnerPL then
begin
BiggestWinnerPL := OrderProfit;
BiggestWinnerTicket := OrderTicket;
BiggestWinnerType := OrderType;
BiggestWinnerSymbol := OrderSymbol;
end
if OrderProfit < BiggestLoserPL then
begin
BiggestLoserPL := OrderProfit;
BiggestLoserTicket := OrderTicket;
BiggestLoserType := OrderType;
BiggestLoserSymbol := OrderSymbol;
end
end
end
end
exports
InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick;
end.
is this really due to my coding error or my mistake in using Borland Delphi 7? When I compile, the code is '.dpr' format.
Many thanks in advance! Looking forward to any suggestions!