Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (dr_panther, Quad, AndrewAMD, 7th_zorro), 945 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Need help to fix some error in my code #487615
06/16/23 01:52
06/16/23 01:52
Joined: Jun 2023
Posts: 1
Abu Dhabi
V
Vkvishal Offline OP
Guest
Vkvishal  Offline OP
Guest
V

Joined: Jun 2023
Posts: 1
Abu Dhabi
I am not able to compline and test this script due to some erros
Line 27,28,and 31
< void run()
>.

Trade1 compiling........
Error in 'line 27:
Redefined with different type: Stoch
< var StochK, StochD, Stoch;
>
Error in 'line 28:
Redefined with different type: ATR
< var ATR, StopLoss; 14
>
Error in 'line 31:
syntax error
< bool isEntry()
>.




// Zorro Trader Trading Script - 3 SMA, Stochastic, and ATR Strategy with Risk Management

// Include files
#include <default.c>
#include <performance.c>

// Strategy parameters
int FastPeriod = 10; // Fast SMA period
int MediumPeriod = 20; // Medium SMA period
int SlowPeriod = 50; // Slow SMA period
int StochPeriod = 14; // Stochastic Oscillator period
int ATRPeriod = 14; // ATR period
double EntryThreshold = 30.0; // Stochastic entry threshold
double ExitThreshold = 70.0; // Stochastic exit threshold
double ATRStopLossFactor = 1.5; // ATR stop loss factor

// Risk management parameters
double RiskPercent = 1.0; // Risk as a percentage of the account balance
double StopLossPercent = 2.0; // Stop loss as a percentage of the trade entry price

// Global variables
var BalancePercent = 0.01; // Lot size as a percentage of the account balance
var LotSize = 0; // Calculated lot size based on account balance

// Indicator variables
var FastSMA, MediumSMA, SlowSMA;
var StochK, StochD, Stoch;
var ATR, StopLoss; 14

// Entry condition
bool isEntry()
{
// Calculate the SMA values
FastSMA = SMA(C, FastPeriod);10
MediumSMA = SMA(C, MediumPeriod);
SlowSMA = SMA(C, SlowPeriod);

// Calculate the Stochastic Oscillator values
StochK = Stoch(StochPeriod);
StochD = MA(StochK, 3);
Stoch = StochK * 100;

// Calculate the ATR value
ATR = ATR(ATRPeriod);

// Check for entry condition
return CrossOver(FastSMA, MediumSMA) && CrossOver(FastSMA, SlowSMA) && Stoch < EntryThreshold;
}

// Exit condition
bool isExit()
{
// Check for exit condition
return CrossUnder(FastSMA, MediumSMA) && CrossUnder(FastSMA, SlowSMA) || Stoch > ExitThreshold;
}

// Risk management
void manageRisk()
{
// Calculate the stop loss level based on the ATR value
StopLoss = EntryPrice - ATRStopLossFactor * ATR;

// Set the stop loss level
setStopLoss(StopLoss);
}

// Update function
void update()
{
// Implement your custom update logic here
// You can add additional risk management rules, advanced features, and other trading rules

// Example: Implement dynamic lot sizing based on account balance
LotSize = Balance * BalancePercent / (StopLossPercent * ATR);
if (LotSize < 1) LotSize = 1;
if (LotSize > 100) LotSize = 100;
setf(LOT, LotSize);
}

// Main function
void run()
{
while (asset(loop("EUR/USD", "GBP/USD", "USD/JPY")))
{
if (isEntry())
{
enterLong();
manageRisk();
}
else if (isExit())
{
exitLong();
}

// Call the update function
update();

// Wait for the next bar
wait(1);
}
}

// Performance report
void report()
{
BarPeriod = 1440; // Set bar period to daily
PlotWidth = 800; // Set plot width for the performance report

set(TESTNOW);
set(PLOTNOW);
set(PLOTRESULTS);

while (asset(loop("EUR/USD", "GBP/USD", "USD/JPY")))
{
if (is(INITRUN))
{
plot("Equity", Equity, NEW, BLUE);
plot("Balance", Balance, 0, RED);
plot("Trades", Trades, LINE, GREEN);
}

// Wait for the next bar
wait(1);
}
}

// Main function
void main()
{
// Initialize the Zorro Trader engine
set(LOGFILE, "log.txt"); // Set the log file name
set(PARAMETERS, 2); // Enable variable parameters
set(TICKS, 0); // Use bar data for trading
set(PLOTNOW); // Enable real-time plotting
set(TRADEMODE, TRADE_ASSET); // Set trade mode to asset trading

// Set the lot size
LotSize = Balance * BalancePercent / (StopLossPercent * ATR);
if (LotSize < 1) LotSize = 1;
setf(LOT, LotSize);

// Run the trading logic
run();

// Generate the performance report
report();

// Shutdown the Zorro Trader engine
quit("Trading completed");
}

Last edited by Vkvishal; 06/16/23 01:57.
Re: Need help to fix some error in my code [Re: Vkvishal] #487616
06/16/23 09:57
06/16/23 09:57
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
Look at the line:

var ATR, StopLoss; 14

The compiler has no clue on how to interpret '14'.
Maybe you mean 'var ATR, StopLoss = 14;' or 'var ATR, StopLoss; //14' ?


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1