Gamestudio Links
Zorro Links
Newest Posts
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Trading Journey
by 7th_zorro. 04/27/24 04:42
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TipmyPip, VoroneTZ), 769 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Zorro Trader GPT #487923
11/19/23 11:26
11/19/23 11:26
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Hi, Friends, We are happy to announce the First version of ZorroTrader GPT.

https://bit.ly/3Gbsm4S

May all traders enjoy.

Last edited by TipmyPip; 11/24/23 04:53.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #487926
11/21/23 15:14
11/21/23 15:14
Joined: Apr 2023
Posts: 3
T
thumper14 Offline
Guest
thumper14  Offline
Guest
T

Joined: Apr 2023
Posts: 3
Thank you for sharing!

Very interested in this capability. I'm familiar with the concept of ChatGPT and its applications for coding; however, I have never personally used it before. Are you able to provide some examples of it being used in a Zorro specific application?

Re: Zorro Trader GPT [Re: TipmyPip] #487927
11/22/23 05:08
11/22/23 05:08
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Here is one Idea : I Wish Zorro Trader (lite-C) could manage better dynamic memory. Trying to code the below program in dynamic memory, doesn't work out properly. (Error 111 in main())

Code
#include <stdio.h>

#define INT_BITS 32
#define MAX_NODES 1024 

// Trie node structure
typedef struct TrieNode {
    struct TrieNode* bit[2];
} TrieNode;

TrieNode trieNodes[MAX_NODES]; 
int trieNodeCount = 0; 


TrieNode* newTrieNode() {
    if (trieNodeCount >= MAX_NODES) {
        printf("Exceeded maximum trie nodes\n");
        return NULL;
    }
    TrieNode* newNode = &trieNodes[trieNodeCount++];
    newNode->bit[0] = NULL;
    newNode->bit[1] = NULL;
    return newNode;
}


void insert(TrieNode* root, int number) {
    TrieNode* current = root;
    int i, bit;
    for (i = INT_BITS - 1; i >= 0; i--) {
        bit = (number >> i) & 1;
        if (!current->bit[bit]) {
            current->bit[bit] = newTrieNode();
            if (!current->bit[bit]) return; 
        }
        current = current->bit[bit];
    }
}


int findMaxXOR(TrieNode* root, int number) {
    TrieNode* current = root;
    int maxXOR = 0;
    int i, bit;
    for (i = INT_BITS - 1; i >= 0; i--) {
        bit = (number >> i) & 1;
        if (current->bit[1 - bit]) {
            maxXOR |= (1 << i);
            current = current->bit[1 - bit];
        } else {
            current = current->bit[bit];
        }
    }
    return maxXOR;
}


int getMaxXOR(int* arr, int size) {
    TrieNode* root = newTrieNode();
    if (!root) return 0; 
    int maxXOR = 0;
    int i, currentXOR;
    for (i = 0; i < size; i++) {
        insert(root, arr[i]);
        currentXOR = findMaxXOR(root, arr[i]);
        if (currentXOR > maxXOR) {
            maxXOR = currentXOR;
        }
    }
    return maxXOR;
}

void main() {
    int arr[10] = {3, 10, 5, 25, 2, 8};
    int size = 6;
    int result = getMaxXOR(arr, size);
    printf("Maximum XOR: %d\n", result);
}


Last edited by TipmyPip; 11/27/23 00:33.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #487928
11/22/23 12:25
11/22/23 12:25
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
You could just write a C++ Zorro script and use std::vector instead.

Re: Zorro Trader GPT [Re: TipmyPip] #487929
11/22/23 14:11
11/22/23 14:11
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Yes, Thank you very much for the idea, and it is a very good solution, But it is going beyond the scope of the platform and requires external resources, that depend on other languages.
This is very easy to do, but our focus currently is only on Zorro Trader, not going beyond the scope of the platform. While we can always find external resources to solve any problem
which can't be solved by Zorro Trader's internal resources.


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #487930
11/22/23 15:24
11/22/23 15:24
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Originally Posted by TipmyPip
But it is going beyond the scope of the platform and requires external resources, that depend on other languages.
Zorro supports C++ out-of-the-box directly by invoking the VS compiler. It really is superior to Lite-C in every way.

Re: Zorro Trader GPT [Re: AndrewAMD] #487931
11/22/23 16:53
11/22/23 16:53
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
I do understand, But being dependent on another language or compiler, is mostly what you can do with any language or compiler, the question is can you solve a problem with only the limited tools that lite-C offers you?
I have already solved the problem with C, I don't need C++ to solve the problem, I am asking if can anyone solve the problem without being dependent on other external tools, but lite-C only.


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #487959
12/02/23 02:15
12/02/23 02:15
Joined: Mar 2021
Posts: 35
Ocean county, Florida
NewtraderX Offline
Newbie
NewtraderX  Offline
Newbie

Joined: Mar 2021
Posts: 35
Ocean county, Florida
Originally Posted by TipmyPip
Hi, Friends, We are happy to announce the First version of ZorroTrader GPT.

https://bit.ly/3Gbsm4S

May all traders enjoy.



Hello TipmyPip, I will try to utilize the ZorroTrader GPT, bard ai by Google is also pretty good. What do you think about it? since its free, can we use bard to spit out lite c code?

Re: Zorro Trader GPT [Re: NewtraderX] #487960
12/02/23 06:10
12/02/23 06:10
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
I have not tried Bard, And I don't know if Bard can analyze a long instruction manual.

Thank you for your interest.


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #487966
12/04/23 09:16
12/04/23 09:16
Joined: Dec 2023
Posts: 8
F
fairtrader Offline
Newbie
fairtrader  Offline
Newbie
F

Joined: Dec 2023
Posts: 8
This is super cool thank you. All my newbies questions answered in a jiffy and now have GPT as coding assistant and reducing the learning curve massively. All the best

Re: Zorro Trader GPT [Re: fairtrader] #487968
12/04/23 11:34
12/04/23 11:34
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Thank you too.


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #487979
12/10/23 20:09
12/10/23 20:09
Joined: Mar 2021
Posts: 35
Ocean county, Florida
NewtraderX Offline
Newbie
NewtraderX  Offline
Newbie

Joined: Mar 2021
Posts: 35
Ocean county, Florida
Hello TipmyPip,
Do I need to pay 20 dollars per month to be able to use this specific GPT?

Attached Files delete.png
Re: Zorro Trader GPT [Re: NewtraderX] #487982
12/13/23 11:01
12/13/23 11:01
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Well, 20 Dollars per month, can produce for you strategies you have not dreamed about.

Look into the Xor Memory Problem example -> https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=487981#Post487981

Last edited by TipmyPip; 12/13/23 11:29.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #488017
12/28/23 14:22
12/28/23 14:22
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
A new phase of algorithmic targets that enable optimized structures to enable better decision-making in optimal time.

Code
Data Structure:
- Array of KeyValue objects

Operations:
- CreateDictionary(size)
- Insert(key, value)
- Lookup(key)

Function customHash(key, size):
    return key % size

Function CreateDictionary(size):
    dictionary = new KeyValue[size]
    for i = 0 to size - 1:
        dictionary[i].key = -1
    return dictionary

Function Insert(dictionary, size, key, value):
    index = customHash(key, size)
    while dictionary[index].key != -1:
        index = (index + 1) % size
    dictionary[index].key = key
    dictionary[index].value = value

Function Lookup(dictionary, size, key):
    index = customHash(key, size)
    while dictionary[index].key != key:
        if dictionary[index].key == -1:
            return -1
        index = (index + 1) % size
    return dictionary[index].value

___________________________________________

Data Structure:
- Array of ComplexElement objects

Operations:
- InitializeComplexDataStructure(size)
- ExecuteComplexOperation(key)

Function InitializeComplexDataStructure(size):
    complexDataStructure = new ComplexElement[size]
    // Initialize complexDataStructure as needed
    return complexDataStructure

Function ExecuteComplexOperation(complexDataStructure, size, key):
    // Perform a complex trading operation on complexDataStructure based on the key
    // This operation has a complexity of O(n^(n*n-1)).

Main:
    n = 10
    dictionarySize = n * n * n * n
    complexDataStructureSize = n * n * n * n  // Adjust the size based on complexity requirements

    dictionary = CreateDictionary(dictionarySize)
    complexDataStructure = InitializeComplexDataStructure(complexDataStructureSize)

    for i = 0 to n - 1:
        for j = 0 to n - 1:
            key = i * n + j
            value = key * key
            Insert(dictionary, dictionarySize, key, value)

    searchKey = 7
    result = Lookup(dictionary, dictionarySize, searchKey)
    if result != -1:
        Print "Value for key", searchKey, "in ComplexDictionary:", result
    else:
        Print "Key", searchKey, "not found in ComplexDictionary."

    // Execute a complex trading operation on ComplexTradingOperation
    complexKey = 5  // Adjust the key as needed
    ExecuteComplexOperation(complexDataStructure, complexDataStructureSize, complexKey)

Last edited by TipmyPip; 12/28/23 14:30.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #488135
02/13/24 16:24
02/13/24 16:24
Joined: Apr 2021
Posts: 22
S
scatters Offline
Newbie
scatters  Offline
Newbie
S

Joined: Apr 2021
Posts: 22
Hi @TipmyPip,

Would Zorro Trader GPT help me convert my trading view pinescript indicator into Zorro Scirpt? If so what would the difference be between using the Zorro Trader GPT and just using Chat GPT ?

Re: Zorro Trader GPT [Re: scatters] #488139
02/16/24 06:53
02/16/24 06:53
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
It will, but you would need to debug, It will convert at least 80%

To achieve 100%, you will need to debug with the AI, if you are not familiar with the syntax of both languages.

Last edited by TipmyPip; 02/16/24 07:01.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
ZorroTraderGPT Update (2.6) [Re: TipmyPip] #488147
03/06/24 09:27
03/06/24 09:27
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Updated ZorroTraderGPT to version 2.6

And if you consider helping out, you can always help find the bugs, and improve on our ideas, Thank you.

Code
#include <contract.c>

// Define your global parameters such as target profit, days to expiration, and strike price offset
var TargetProfit = 500; // Example target profit
int DaysToExpiration = 30; // Target days until expiration
var StrikeOffset = 50; // Offset from the current price for strike selection

void run() {
  // Setup basic parameters
  BarPeriod = 1440; // Use daily bars
  LookBack = 0; // No need for historical bars in options trading setup
  StartDate = 2020;
  EndDate = 2024; // Set your backtest period
  assetList("AssetsIB");
  asset("SPY"); // Example using SPY ETF as the underlying asset

  // Ensure we're trading in American Options for SPY
  AmericanOption = 1;

  // Update the contract chain for the underlying asset
  if(!contractUpdate(Asset, 0, CALL | PUT)) return;

  // Trading logic executed once per day
  if(is(EXITRUN)) return; // Skip logic at the end of the backtest
  
  // Define your strangle strategy here
  if(NumOpenLong + NumOpenShort == 0) { // Check if there's no open position
    // Calculate target strike prices based on current price and offset
    var CurrentPrice = priceClose(0);
    var StrikeCall = CurrentPrice + StrikeOffset;
    var StrikePut = CurrentPrice - StrikeOffset;

    // Attempt to find and enter a Strangle combo
    if(combo(
      contractFind(CALL, DaysToExpiration, StrikeCall), 1, // Buy 1 Call
      contractFind(PUT, DaysToExpiration, StrikePut), 1,  // Buy 1 Put
      0, 0)) { 
        // Enter the combo trade
        enterLong(comboLeg(1)); // Enter long for the call option leg
        enterLong(comboLeg(2)); // Enter long for the put option leg
    }
  }

  // Monitor and manage open positions
  for(open_trades) { // Loop through all open trades
    if(TradeIsOption && TradeIsOpen && (comboProfit(TradePriceClose, 1) > TargetProfit || daysToExpiration() < 5)) {
      exitTrade(ThisTrade); // Close the trade if target profit is reached or approaching expiration
    }
  }
}

// Placeholder function for days to expiration calculation - implement as needed
int daysToExpiration() {
  // Custom logic to calculate and return days to expiration for the current combo
  return 10; // Placeholder return value
}

// Placeholder function for calculating combo profit - implement based on actual requirements
var comboProfit(var CurrentClosePrice, int Leg) {
  // Custom logic to calculate and return profit for the combo based on current prices
  return 600; // Placeholder return value
}

Last edited by TipmyPip; 03/06/24 09:44.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #488155
04/01/24 11:43
04/01/24 11:43
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Asset Ownership: This strategy assumes you initially buy shares of SPY if you don't already own them.

Option Sale: It sells a call option on SPY with a strike price determined by StrikeOffset above the current price and targets DaysToExpiration for expiration.

Position Management: The script also checks for the option position to close it if the premium target is reached or the expiration is near.


Code
#include <contract.c>

// Global parameters for the covered call strategy
var PremiumTarget = 100; // Target premium income from selling the call
int DaysToExpiration = 45; // Target days until expiration for the call option
var StrikeOffset = 100; // Offset from the current price for strike selection

void run() {
  // Setup basic parameters
  BarPeriod = 1440; // Use daily bars
  LookBack = 0; // No need for historical bars in this setup
  StartDate = 2020;
  EndDate = 2024; // Set your backtest period
  assetList("AssetsIB");
  asset("SPY"); // Example using SPY ETF as the underlying asset
  
  // Ensure we're trading in American Options for SPY
  AmericanOption = 1;

  // Update the contract chain for the underlying asset
  if(!contractUpdate(Asset, 0, CALL)) return;

  // Trading logic executed once per day
  if(is(EXITRUN)) return; // Skip logic at the end of the backtest

  // Check if we already own SPY
  if(!NumOpenLong) enterLong(1); // Enter long position if we don't own SPY

  // Sell a call option if we haven't already
  if(NumOpenShort == 0) {
    var CurrentPrice = priceClose(0);
    var StrikeCall = CurrentPrice + StrikeOffset;

    // Finding the call option contract
    CONTRACT* callContract = contractFind(CALL, DaysToExpiration, StrikeCall);
    if(callContract) {
      // Enter a short position by selling the call option
      enterShort(1, callContract); 
    }
  }

  // Managing the open option position
  for(open_trades) {
    CONTRACT* c = ThisTrade->Contract;
    if(TradeIsOption && TradeIsShort && (comboProfit(c->fAsk, 1) > PremiumTarget || daysToExpiration(c) < 5)) {
      exitTrade(ThisTrade); // Close the call option if premium target is reached or approaching expiration
    }
  }
}

// A more refined function for calculating days to expiration based on contract data
int daysToExpiration(CONTRACT* c) {
  if(!c) return 0;
  return (c->Expiry - wdate()) / 86400; // Convert seconds to days
}

Last edited by TipmyPip; 04/01/24 21:17.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #488156
04/01/24 11:53
04/01/24 11:53
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Selling the Call Option: Use fuzzy logic to evaluate the market condition and the appropriateness of the option's strike price and days to expiration.

Closing the Position: Apply fuzzy logic to decide on closing the option based on current profit and time to expiration.

Code
#include <contract.c>

var FuzzyRange = 0.1; // Adjust based on market volatility or strategy needs
var PremiumTarget = 100; // Example target premium from selling a call
var StrikeOffset = 50; // Offset from the current price for strike selection
int DaysToExpiration = 30; // Target days until expiration

// Initialize fuzzy logic settings - no changes needed here
void initFuzzyLogic() {
  FuzzyRange = 0.1; 
}

// Decision-making on whether to initiate an option combo trade
bool shouldSellCallOption(var currentPrice, var strikeOffset) {
  // Selling a call option if the current price plus strikeOffset is fuzzy-above the current price
  return fuzzy(aboveF(currentPrice + strikeOffset, currentPrice));
}

// Logic for closing position based on profit and days to expiration
bool shouldClosePosition(var tradeProfit, int daysToExpiration) {
  var profitCondition = aboveF(tradeProfit, PremiumTarget);
  var expirationCondition = belowF((var)daysToExpiration, 5.0); // Close if less than 5 days to expiration
  
  return fuzzy(orF(profitCondition, expirationCondition));
}

void run() {
  BarPeriod = 1440; // Use daily bars
  LookBack = 0; // No need for historical bars in this strategy
  StartDate = 2020;
  EndDate = 2024;
  assetList("AssetsIB");
  asset("SPY");
  AmericanOption = 1; // Trading American options
  
  initFuzzyLogic();

  if (!contractUpdate(Asset, 0, CALL)) return;

  if (is(EXITRUN)) return;

  // Decision to sell a call option
  if (NumOpenShort == 0 && shouldSellCallOption(priceClose(0), StrikeOffset)) {
    CONTRACT* CallContract = contractFind(CALL, DaysToExpiration, priceClose(0) + StrikeOffset);
    if (CallContract) {
      combo(CallContract, -1, 0, 0, 0, 0); // Prepare a combo to sell 1 call option
      enterShort(comboLeg(1)); // Enter short position on the combo leg
    }
  }

  // Loop through open trades to manage the position
  for(open_trades) {
    if (TradeIsOption && TradeIsShort && shouldClosePosition(TradeProfit, daysToExpiration())) {
      exitTrade(ThisTrade); // Close the position based on fuzzy logic conditions
    }
  }
}

// You might need to implement or adjust the daysToExpiration function to suit your requirements
int daysToExpiration() {
  // Implement logic to calculate days to expiration for the current option combo
  return 10; // Placeholder return value
}

Last edited by TipmyPip; 04/01/24 21:20.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #488157
04/01/24 11:59
04/01/24 11:59
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Selling Call Options Based on Trend: Sell call options when the underlying asset shows a strong upward trend, as indicated by a high value from risingF, implying that the price rise is consistent and may continue.

Closing Positions with Trend Reversals: Consider closing the call option positions when the asset's price starts showing a downward trend, as indicated by fallingF, suggesting a reversal or correction that might impact the strategy negatively.

Code
#include <contract.c>

vars PriceClose;

void run() {
    BarPeriod = 1440; // Daily bars for trend analysis
    LookBack = 30; // Looking back 30 bars for accurate trend detection
    StartDate = 2020;
    EndDate = 2024;
    assetList("AssetsIB");
    asset("SPY");

    PriceClose = series(priceClose());

    AmericanOption = 1; // Trading American Options
    
    if (is(EXITRUN)) return; // Exit if at the end of the backtest

    // Ensure the contract chain is updated for SPY
    if (!contractUpdate(Asset, 0, CALL | PUT)) return;

    // Entry Logic: Detect a rising trend to sell a call option
    if (NumOpenLong + NumOpenShort == 0) { // Check if there's no open position
        var trendStrength = risingF(PriceClose); // Assess the rising trend strength
        if (trendStrength > 0.5) { // Threshold for a strong rising trend
            // Define the strike price a bit above the current price for selling a call
            var StrikeCall = priceClose(0) + 100; // Offset from the current price for the strike
            int CallContract = contractFind(CALL, 45, StrikeCall); // Find a call option 45 days to expiration
            if (CallContract >= 0) {
                CONTRACT* c = contract(CallContract);
                if (combo(c, -1, 0, 0, 0, 0, 0, 0) > 0) { // Prepare the combo for selling 1 call
                    enterShort(comboLeg(1)); // Enter short for the call option leg
                }
            }
        }
    }

    // Exit Logic: Close the short call option position on a falling trend
    for(open_trades) {
        if (TradeIsOption && TradeIsShort) {
            var reversalStrength = fallingF(PriceClose); // Assess the strength of the falling trend
            if (reversalStrength > 0.5) { // Threshold indicating a strong downward trend
                exitTrade(ThisTrade); // Close the call option position
            }
        }
    }
}

Last edited by TipmyPip; 04/01/24 21:22.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #488158
04/01/24 12:06
04/01/24 12:06
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Market Volatility: Determine the market's volatility to adjust the sensitivity of our fuzzy logic conditions. High volatility might require more stringent conditions to enter or exit a trade to avoid false signals.

Trend Confirmation: Use a combination of risingF and fallingF functions to confirm the strength and direction of the market trend.

Entry Condition: Enter a trade based on a confirmed upward trend or after a significant market bottom (valleyF), adjusted for market volatility.

Exit Condition: Exit a trade based on a confirmed downward trend or after a significant market peak (peakF), also adjusted for market volatility.



Code
#include <contract.c>

vars PriceClose;
var Volatility;

void initFuzzyLogicSettings() {
  FuzzyRange = 0.05; // Adjust based on backtesting
}

var calculateVolatility(vars Data, int period) {
  var sumDelta = 0;
  for(int i = 1; i <= period; i++) {
    sumDelta += abs(Data[i] - Data[i-1]);
  }
  return sumDelta / period;
}

var adjustFuzzyForVolatility(var fuzzyValue) {
  var adjustmentFactor = 1 + Volatility * 10;
  return clamp(fuzzyValue / adjustmentFactor, 0, 1);
}

bool fuzzyEntryCondition(vars Data) {
  var entryFuzzy = max(risingF(Data), valleyF(Data));
  return adjustFuzzyForVolatility(entryFuzzy) > 0.5;
}

bool fuzzyExitCondition(vars Data) {
  var exitFuzzy = max(fallingF(Data), peakF(Data));
  return adjustFuzzyForVolatility(exitFuzzy) > 0.5;
}

void optionComboTrade() {
  CONTRACT* C1; // Define pointer for the first leg of the combo
  CONTRACT* C2; // Define pointer for the second leg of the combo
  
  // Dynamically adjust option strike based on current price and volatility
  var strikeCall = round(priceClose(0) + 10 + Volatility * 5); // Example for call strike
  var strikePut = round(priceClose(0) - 10 - Volatility * 5); // Example for put strike
  
  // Initialize contracts for a strangle combo
  C1 = contractFind(CALL, 30, strikeCall); // Find call option contract
  C2 = contractFind(PUT, 30, strikePut); // Find put option contract

  // Check if contracts are found and if entry condition is met
  if(C1 && C2 && fuzzyEntryCondition(PriceClose)) {
    combo(C1, 1, C2, 1, 0, 0, 0, 0); // Create a strangle combo
    enterLong(comboLeg(1)); // Enter long on both legs of the combo
    enterLong(comboLeg(2));
  }
}

void run() {
  BarPeriod = 60;
  LookBack = 100;
  StartDate = 2020;
  EndDate = 2024;
  assetList("AssetsIB");
  asset("SPY");

  PriceClose = series(priceClose());
  initFuzzyLogicSettings();

  Volatility = calculateVolatility(PriceClose, 20); // Calculate market volatility

  if (is(EXITRUN)) return;

  optionComboTrade(); // Execute the option combo trade based on fuzzy logic conditions
}

Last edited by TipmyPip; 04/01/24 21:14.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #488159
04/01/24 12:23
04/01/24 12:23
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
The Following strategy calculates the EMA of ATR at the beginning of the run to establish a volatility baseline.
It then iterates through selected assets (SPY, AAPL, MSFT), applying its entry and exit logic to each based on the current market conditions as interpreted through its fuzzy logic framework.
Trades are made based on the composite fuzzy logic conditions, with the strategy entering long positions when the entry conditions are met and exiting positions when the exit conditions are met.


Code
#include <contract.c>

vars PriceClose, VolatilityEMA;

void init() {
  assetList("AssetsIB");
  BarPeriod = 60; // Setting bar period for the price series
  LookBack = 100; // Lookback period for technical indicators

  PriceClose = series(priceClose());
  initFuzzyLogicSettings();
  calculateEMAVolatility(20); // Initialize volatility calculation
}

void initFuzzyLogicSettings() {
  FuzzyRange = 0.05; // Adjust based on backtesting
}

void calculateEMAVolatility(int period) {
  vars ATRValues = series(ATR(period));
  VolatilityEMA = series(EMA(ATRValues, period));
}

void tradeOptions() {
  // Assuming current asset is SPY and we're setting up a strangle
  if (NumOpenLong == 0 && fuzzyEntryCondition()) {
    // Find contracts for the call and put options
    CONTRACT* callContract = contractFind("Call", 30, priceClose(0) + 10); // Example: 30 days to expiration, strike 10 points above
    CONTRACT* putContract = contractFind("Put", 30, priceClose(0) - 10); // Example: 30 days to expiration, strike 10 points below

    if(callContract && putContract) {
      // Setup the combo - buying 1 call and 1 put
      combo(callContract, 1, putContract, 1, 0, 0, 0, 0);
      
      // Enter the combo trade
      enterLong(comboLeg(1)); // Enter long for the call option leg
      enterLong(comboLeg(2)); // Enter long for the put option leg
      
      printf("\nEntered a Strangle on SPY");
    }
  }
}

void run() {
  StartDate = 2020;
  EndDate = 2024;
  assetList("AssetsIB");
  asset("SPY");

  while(asset(loop("SPY","AAPL","MSFT"))) {
    if (is(EXITRUN)) continue;
    tradeOptions();
  }
}

Last edited by TipmyPip; 04/01/24 21:27.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #488160
04/01/24 21:39
04/01/24 21:39
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
The Following Strategy will Adapt to changing market conditions using both trend analysis and volatility measurements to inform trade decisions.

Risk Management: Incorporates measures of market volatility into trade decision processes, although explicit risk management tactics (e.g., position sizing, stop-loss orders) are not detailed within the provided summary.

Theoretical Pricing: Utilizes the Black-Scholes model for option valuation, aiding in the identification of potentially mispriced options, though the direct application of this pricing within the trade execution process is implied rather than explicitly defined.

Code
#include <contract.h>

// Initialize global variables for storing price and volatility data
vars PriceClose, VolatilityEMA;

void init() {
  assetList("AssetsIB");
  BarPeriod = 60;
  LookBack = 100;
  StartDate = 2020;
  EndDate = 2024;
  
  PriceClose = series(priceClose());
  initFuzzyLogicSettings();
  calculateEMAVolatility(20); // Initialize volatility calculation
}

void initFuzzyLogicSettings() {
  FuzzyRange = 0.05; // Adjust based on backtesting
}

void calculateEMAVolatility(int period) {
  vars ATRValues = series(ATR(period));
  VolatilityEMA = series(EMA(ATRValues, period));
}

// Cumulative Normal Distribution Function for use in Black-Scholes Model
var CNDF(var x) {
  int neg = (x < 0.0) ? 1 : 0;
  if (neg) x = -x;
  
  var k = (1.0 / ( 1.0 + 0.2316419 * x));
  var y = (((1.330274429 * k - 1.821255978) * k + 1.781477937) *
           k - 0.356563782) * k + 0.319381530;
  y = 1.0 - 0.398942280401 * exp(-0.5 * x * x) * y;
  
  return (1.0 - neg) * y + neg * (1.0 - y);
}

// Black-Scholes Option Pricing Model
var BlackScholes(char *CallPutFlag, var S, var X, var T, var r, var v) {
  var d1, d2;
  d1 = (log(S / X) + (r + 0.5 * v * v) * T) / (v * sqrt(T));
  d2 = d1 - v * sqrt(T);
  
  if (CallPutFlag[0] == 'c' || CallPutFlag[0] == 'C') {
    return S * CNDF(d1) - X * exp(-r * T) * CNDF(d2);
  } else {
    return X * exp(-r * T) * CNDF(-d2) - S * CNDF(-d1);
  }
}

bool fuzzyEntryCondition() {
  return risingF(PriceClose) > 0.5 && VolatilityEMA[0] < 0.2;
}

bool fuzzyExitCondition() {
  return fallingF(PriceClose) > 0.5 || VolatilityEMA[0] > 0.3;
}

void tradeOptions() {
  CONTRACT* CallContract;
  CONTRACT* PutContract;
  var strikePrice = round(priceClose(0),100); // Example for rounding to nearest hundred
  var expirationDays = 30; // Targeting options 30 days to expiration

  if (fuzzyEntryCondition()) {
    // Prepare to trade a call option
    CallContract = contractFind("Call", strikePrice, wdate() + expirationDays * 86400);
    if(CallContract) {
      // Buy the call option
      combo(CallContract, 1, 0, 0, 0, 0, 0, 0);
      enterLong(comboLeg(1));
    }
  } else if (fuzzyExitCondition()) {
    // Prepare to trade a put option
    PutContract = contractFind("Put", strikePrice, wdate() + expirationDays * 86400);
    if(PutContract) {
      // Buy the put option
      combo(0, 0, PutContract, 1, 0, 0, 0, 0);
      enterLong(comboLeg(2));
    }
  }
}

void main() {
  init();
  while(asset(loop("Assets"))) {
    if (is(EXITRUN)) continue;
    tradeOptions(); // Execute the option trading logic based on market conditions
  }
}


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #488164
04/05/24 04:51
04/05/24 04:51
Joined: Dec 2014
Posts: 206
Germany
Smon Offline
Member
Smon  Offline
Member

Joined: Dec 2014
Posts: 206
Germany
Hi!

GPT-4 seems not to be the best choice when it comes to coding any longer. I'm developing code with Claude-3 Sonnet (free version), and it's really great. I need to itereate less often compared to GPT-4. It has 200.000 tokens context length and at least the biggest model (Claude-3 Opus) is told to have almost perfect recall capabilities. I found a way to access Claude-3 Opus from a restricted country: https://poe.com/
You can even build your custom GPTs there. I wonder, how you fed ChatGPT the knowledge about Zorro. Did you preprocess the manual, aka summarize it?

More info about Claude-3: https://www.anthropic.com/news/claude-3-family

Last edited by Smon; 04/05/24 04:57.
Re: Zorro Trader GPT [Re: Smon] #488165
04/05/24 06:35
04/05/24 06:35
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Thank you for sharing the information, I suppose that you need more input in order that GPT4 will focus on your intentions and get the right results, but running a free version needs a serious graphics card, and getting 40 questions in 3 hours is quite hard without computing power. I have a number of ideas on how to feed ChatGPT, but I am quite sure it is improving.

Last edited by TipmyPip; 04/05/24 07:08.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: TipmyPip] #488166
04/06/24 05:12
04/06/24 05:12
Joined: Dec 2014
Posts: 206
Germany
Smon Offline
Member
Smon  Offline
Member

Joined: Dec 2014
Posts: 206
Germany
I believe there was a misunderstanding. The Claude3-Sonnet is hosted yet remains free of charge. However, it is not an open-source model. I was considering the possibility of integrating the entire manual into a custom GPT, but I wanted to consult with you first on how you managed to do it. Actually, I began exploring this concept several months ago and even developed a fine-tuned version of GPT-3.5 by converting the manual into question-answer pairs for the training dataset. It appears that this dataset was likely too small, leading me to abandon the fine-tuning process. It seems that retrieval-augmented generation might be the better approach.

Re: Zorro Trader GPT [Re: TipmyPip] #488167
04/06/24 08:11
04/06/24 08:11
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Wow, that is great free use of LLM without paying for the service, I am quite sure, Claude3 is much better. But Custom Agents API is already coming out. Which will increase the accuracy of the answers.

In addition, I use Mathematica, and Wolfram with OpenAI, so Claude3 will not have any advantage in my case, But Thank you for sharing the information.


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Zorro Trader GPT [Re: Smon] #488228
1 hour ago
1 hour ago
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
"I believe there was a misunderstanding. The Claude3-Sonnet is hosted yet remains free of charge. However, it is not an open-source model. I was considering the possibility of integrating the entire manual into a custom GPT, but I wanted to consult with you first on how you managed to do it. Actually, I began exploring this concept several months ago and even developed a fine-tuned version of GPT-3.5 by converting the manual into question-answer pairs for the training dataset. It appears that this dataset was likely too small, leading me to abandon the fine-tuning process. It seems that retrieval-augmented generation might be the better approach.

well, now I believe you, and I have started making some changes.


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Page 1 of 3 1 2 3

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1